Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class EndingInput {
- public static void main(String[] args) {
- // this program will show a way to end input for strings
- Scanner kb = new Scanner(System.in);
- System.out.println("Enter the size of your array");
- int size = kb.nextInt();
- String[] names = new String[size];
- // intialize your string with names
- for (int i=0; i < names.length; i++){
- System.out.println("Enter a name or enter exit to quit");
- String entry = kb.next();
- if (entry.equalsIgnoreCase("exit")){
- break;
- }
- else
- names[i] = entry;
- }
- for (String e: names)
- System.out.print(e+" ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement