InputFromKeyBoard
This commit is contained in:
22
InputFromKeyBoard.java
Normal file
22
InputFromKeyBoard.java
Normal file
@@ -0,0 +1,22 @@
|
||||
// Program to demonstrate input from keyboard using Command line argument.
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
|
||||
public class InputFromKeyBoard {
|
||||
public static void main(String [] args) {
|
||||
int n;
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.print("Enter the number of names you want to store: ");
|
||||
n=sc.nextInt();
|
||||
String[] array = new String[n];
|
||||
System.out.println("Enter the names: ");
|
||||
for(int i=0; i<n; i++) {
|
||||
array[i]=sc.next();
|
||||
}
|
||||
System.out.println("The names are: ");
|
||||
for (String s : array) {
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user