Advertisement
therrontelford

Ending input

Jan 15th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class EndingInput {
  3.  
  4.     public static void main(String[] args) {
  5.         // this program will show a way to end input for strings
  6.         Scanner kb = new Scanner(System.in);
  7.         System.out.println("Enter the size of your array");
  8.         int size = kb.nextInt();
  9.         String[] names = new String[size];
  10.        
  11.        
  12.         // intialize your string with names
  13.         for (int i=0; i < names.length; i++){
  14.             System.out.println("Enter a name or enter exit to quit");
  15.             String entry = kb.next();
  16.  
  17.             if (entry.equalsIgnoreCase("exit")){
  18.                 break;
  19.             }
  20.             else
  21.                 names[i] = entry;
  22.         }
  23.         for (String e: names)
  24.             System.out.print(e+" ");
  25.        
  26.     }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement