Advertisement
SenkuIshigami

Filling an array from the user

Oct 19th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.49 KB | None | 0 0
  1. import java.util.*;
  2. public class test
  3. {
  4.     public static void main(String[] args)
  5.     {
  6.         Scanner in=new Scanner(System.in);
  7.         String []name=new String[50];
  8.         System.out.println("Enter the name of the book, Enter -1 to finish adding books");
  9.         int i=0;
  10.         while(name[i]!=-1)
  11.         {
  12.             name[i]=in.nextLine();
  13.             i++;
  14.         }
  15.         for(i=0;i<name.length;i++)
  16.         {
  17.             System.out.println(name[i]);
  18.         }
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement