Asked by Valerie
I am learning Java in programming right now. I need to write a program that should have an output like this:
The program says "Type ten names". Then ten names sould be typed a person. Then the program chooses a random name from the list and displays it on screen. What should be the Java code for this task? Thank you.
The program says "Type ten names". Then ten names sould be typed a person. Then the program chooses a random name from the list and displays it on screen. What should be the Java code for this task? Thank you.
Answers
Answered by
anonymous
Scanner scan = new Scanner(System.in);
//take 10 string values from user
System.out.println("Enter 10 names: ");
String n = scan.nextLine();
String [] names = new String{n};
//store the names in an array
for (int i = 0; i < 10; i++){
names[i] = scan.nextLine();
}
//sequentially print the names and upperCase them
for (String i : names){
System.out.println(i.toUpperCase());
}
scan.close();
}
//take 10 string values from user
System.out.println("Enter 10 names: ");
String n = scan.nextLine();
String [] names = new String{n};
//store the names in an array
for (int i = 0; i < 10; i++){
names[i] = scan.nextLine();
}
//sequentially print the names and upperCase them
for (String i : names){
System.out.println(i.toUpperCase());
}
scan.close();
}
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.