Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. Package DS;
  2.  
  3. import java.util.*;
  4.  
  5. public class basic_Array {
  6.  
  7. public static void main(String[] args) {
  8.  
  9. int option;
  10.  
  11. System.out.println("Welcome to basic array test, please choose your testing subject: ");
  12.  
  13. Scanner user_option = new Scanner(System.in);
  14.  
  15.  
  16. do{
  17.  
  18. System.out.println("Option 1: Simple one dimensional array.");
  19. System.out.println("Option 2: Simple two dimensional array. (under construction)");
  20. System.out.println("Option 0: Exit program");
  21.  
  22.  
  23. option = user_option.nextInt();
  24. System.out.println("current option is: " + option);
  25.  
  26. switch(option){
  27.  
  28. case 1:
  29. //simple array input method
  30. simple_a1();
  31. break;
  32. case 2:
  33. simple_a2();
  34. break;
  35. }
  36.  
  37.  
  38. }while(option != 0);
  39.  
  40. System.out.println("Program terminated...");
  41. user_option.close();
  42.  
  43. }
  44.  
  45. private static void simple_a1() {
  46.  
  47. int[] a1 = new int[5];
  48.  
  49. int in_num; //redundant but clear.
  50.  
  51. Scanner user_input = new Scanner(System.in);
  52.  
  53. for(int i = 0; i < 5; i++){
  54.  
  55. System.out.println("Request input for item " + i);
  56. in_num = user_input.nextInt();
  57. a1[i] = in_num;
  58. System.out.println("Got it, next one ");
  59. }
  60.  
  61. System.out.println("The numbers in a1 are: ");
  62.  
  63. for(int i2: a1){
  64. System.out.print(i2 + " ");
  65. }
  66.  
  67. System.out.println("nEnd of testing 1, back to main menu...");
  68.  
  69.  
  70. }
  71.  
  72. private static void simple_a2() {
  73.  
  74. System.out.println("This function still under construction, back to main menu...");
  75. }
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement