Read the following code segment and sample output to complete the empty blanks in the code segment. Please note: 1. If the user enters more than one answer, the answers should be separated by comma without any spaces. For example, item1,item2,item3 2. You can assume a perfect user who will give the input with correct format.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
//Display the user's favourite animal (s)
for (int i=0; i<2 i++){
if (animal.charAt(i)==,'){
System.out.print("Your No."+number
+" favourite animal is ");
System.out.println(animal.substring(tag,@)+".");
System.out.print("Your No."+number+" favourite animal is ");
System.out.println(animl.substring(©)+". ");
//Display the number of user's favourite animal (s)
System.out.print("You have ");
System.out.print (number==1?
"one favorite animal!":+number+" favorite animals! ");
//Close the program
Please enter your favourite animal(s):
cat
Your No.1 favourite animal is cat.
You have one favorite animal!
Sample output1
Please enter your favourite animal(s):
cat,dog, tigger,pig, snake
Your No.1 favourite animal is cat.
Your No.2 favourite animal is dog.
Your No.3 favourite animal is tigger.
Your No.4 favourite animal is pig.
Transcribed Image Text://Display the user's favourite animal (s) for (int i=0; i<2 i++){ if (animal.charAt(i)==,'){ System.out.print("Your No."+number +" favourite animal is "); System.out.println(animal.substring(tag,@)+"."); System.out.print("Your No."+number+" favourite animal is "); System.out.println(animl.substring(©)+". "); //Display the number of user's favourite animal (s) System.out.print("You have "); System.out.print (number==1? "one favorite animal!":+number+" favorite animals! "); //Close the program Please enter your favourite animal(s): cat Your No.1 favourite animal is cat. You have one favorite animal! Sample output1 Please enter your favourite animal(s): cat,dog, tigger,pig, snake Your No.1 favourite animal is cat. Your No.2 favourite animal is dog. Your No.3 favourite animal is tigger. Your No.4 favourite animal is pig.
Read the following code segment and sample output to complete the empty blanks in the code
segment.
Please note:
1. If the user enters more than one answer, the answers should be separated by comma
without any spaces. For example, item1,item2,item3
2. You can assume a perfect user who will give the input with correct format.
//Declare variables
Scanner keyIn = new Scanner (System.in) ;
String animal;
int tagw0, number=0;
//Ask the user for inputs
System.out.println ("Please enter your favourite animal (s): ");
animal = @;
//Display the user's favourite animal (s)
for (int i-0; i<0 i++) {
if (animal.charAt(i)==', '){
System.out.print ("Your No. "+number
+" favourite animal is "):
System. out.println (animal.substring (tag, )+"."):
Transcribed Image Text:Read the following code segment and sample output to complete the empty blanks in the code segment. Please note: 1. If the user enters more than one answer, the answers should be separated by comma without any spaces. For example, item1,item2,item3 2. You can assume a perfect user who will give the input with correct format. //Declare variables Scanner keyIn = new Scanner (System.in) ; String animal; int tagw0, number=0; //Ask the user for inputs System.out.println ("Please enter your favourite animal (s): "); animal = @; //Display the user's favourite animal (s) for (int i-0; i<0 i++) { if (animal.charAt(i)==', '){ System.out.print ("Your No. "+number +" favourite animal is "): System. out.println (animal.substring (tag, )+"."):
Expert Solution
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY