60 503
Assignments Done
98,1%
Successfully Done
In April 2018

Answer to Question #23089 in Java | JSP | JSF for lien

Question #23089
kindly help me make a java program that will output 6 pets according to their type. It will first ask the user to enter the type of pet."c" or "d". if the user enters "c" , it will ask the user to enter name for the "cat", else will ask the user to enter name for dog. then output first all cats name, then followed by the list of all dogs name.
Expert's answer
import java.util.Scanner;


public class Output6Pets {

private static Scanner input =new Scanner(System.in);
public static void main(String[] args) {

char ch;
int cointforcat=0;
String namecat[]=new String[100];
int cointfordog=0;
String namedog[]=new String[100];
for(;;){
System.out.print("Please enter 'c' or 'd': ");
ch=input.nextLine().charAt(0);
if(ch=='c'){
System.out.println("Enter name for cat: ");
namecat[cointforcat]=input.nextLine();
cointforcat++;
}
if(ch=='d'){
System.out.println("Enter name for dog: ");
namedog[cointfordog]=input.nextLine();
cointfordog++;
}

for(int i=0;i<cointforcat;i++){

System.out.println(namecat[i]);
}
for(int i=0;i<cointfordog;i++){

System.out.println(namedog[i]);
}
}

}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions