University stuff.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FirstArray.java 1015B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import java.util.Scanner;
  2. class FirstArray {
  3. public static void main(String[] args) {
  4. /*
  5. * A
  6. */
  7. int[] nums = new int[4];
  8. nums[0] = 0;
  9. nums[1] = 1;
  10. nums[2] = 2;
  11. nums[3] = 3;
  12. /*
  13. * B
  14. */
  15. for (int i = 0; i < nums.length; ++i) {
  16. nums[i] = i;
  17. }
  18. /*
  19. * C
  20. */
  21. nums[0] = 1337;
  22. nums[3] = 1337;
  23. /*
  24. * D
  25. */
  26. String[] inputs = new String[5];
  27. Scanner s = new Scanner(System.in);
  28. System.out.println("Enter 5 strings.");
  29. for (int i = 0; i < inputs.length; ++i) {
  30. inputs[i] = s.nextLine();
  31. }
  32. System.out.println("");
  33. /*
  34. * E
  35. */
  36. int i;
  37. //Output the numbers in nums
  38. //For loops would've been appropriate here, but y'know, while loops
  39. System.out.println("Numbers:");
  40. i = 0;
  41. while (i < nums.length) {
  42. System.out.println(nums[i]);
  43. i += 1;
  44. }
  45. System.out.println("");
  46. //Output the strings in inputs
  47. System.out.println("Input strings:");
  48. i = 0;
  49. while (i < inputs.length) {
  50. System.out.println(inputs[i]);
  51. i += 1;
  52. }
  53. }
  54. }