This question already has an answer here:
- Java Scanner ignores answer 2 answers
I don't know where I'm going wrong.
System.out.println("type add to add arrays or type multiply to multiply the arrays");
String m= "multiply";
String a="add";
//String operation=input.nextLine();
if(input.nextLine().equals(m)){
multiply(nums);
}else if(input.nextLine().equals(a)){
add(nums);
}else{
System.out.println("no response");
}
I get the add method to work when i type "add" but it ignores "multiply" and shows no response on the console.
EDIT: I changed it to store input in the variable operation, but it still skips to no response.
System.out.println("type add to add arrays or type multiply to multiply the arrays");
String operation=input.nextLine();
if(operation.equals("multiply")){
multiply(nums);
}else if(operation.equals("add")){
add(nums);
}else{
System.out.println("no response");
}
Aucun commentaire:
Enregistrer un commentaire