-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInpToArr.java
More file actions
27 lines (24 loc) · 786 Bytes
/
InpToArr.java
File metadata and controls
27 lines (24 loc) · 786 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package Array;
import javax.sound.midi.Soundbank;
import java.util.Scanner;
public class InpToArr {
public static void main(String[] args){
// foods[0] = "Pizza";
// foods[1] = "Burger";
// foods[2] = "Cold Drink";
Scanner scanner = new Scanner(System.in);
System.out.print("Enter Number of items you want to add: ");
int num = scanner.nextInt();
String[] foods = new String[num];
for(int i = 0; i < num; i++){
System.out.printf("Enter Item %d: ", i+1);
String item = scanner.next();
foods[i] = item;
}
System.out.println("Your Items are: ");
for(String food : foods){
System.out.print(food + " ");
scanner.close();
}
}
}