Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Package DS;
- import java.util.*;
- public class basic_Array {
- public static void main(String[] args) {
- int option;
- System.out.println("Welcome to basic array test, please choose your testing subject: ");
- Scanner user_option = new Scanner(System.in);
- do{
- System.out.println("Option 1: Simple one dimensional array.");
- System.out.println("Option 2: Simple two dimensional array. (under construction)");
- System.out.println("Option 0: Exit program");
- option = user_option.nextInt();
- System.out.println("current option is: " + option);
- switch(option){
- case 1:
- //simple array input method
- simple_a1();
- break;
- case 2:
- simple_a2();
- break;
- }
- }while(option != 0);
- System.out.println("Program terminated...");
- user_option.close();
- }
- private static void simple_a1() {
- int[] a1 = new int[5];
- int in_num; //redundant but clear.
- Scanner user_input = new Scanner(System.in);
- for(int i = 0; i < 5; i++){
- System.out.println("Request input for item " + i);
- in_num = user_input.nextInt();
- a1[i] = in_num;
- System.out.println("Got it, next one ");
- }
- System.out.println("The numbers in a1 are: ");
- for(int i2: a1){
- System.out.print(i2 + " ");
- }
- System.out.println("nEnd of testing 1, back to main menu...");
- }
- private static void simple_a2() {
- System.out.println("This function still under construction, back to main menu...");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement