0

This is the code:

import java.util.*;

public class Bruce {

 public static void main(String[] args) {
     Scanner tm = new Scanner(System.in); 
     boolean keepGoing = true;
     while(keepGoing) {
         try (Scanner sc = new Scanner(System.in)) {
             System.out.println("What kind of math problem are you trying to solve? A *, /, +, or - problem?");
             String a = sc.nextLine();
             if(a.equals("*")) {
                 System.out.println("What is the first number?");
                 int b = sc.nextInt();
                 System.out.println("What is the second number?");
                 int c = sc.nextInt();
                 int d = b * c;
                 System.out.println("The answer is " + d + ".");
             }
             if(a.equals("/")) {
                 System.out.println("What is the first number?");
                 int e = sc.nextInt();
                 System.out.println("What is the second number?");
                 int f = sc.nextInt();
                 int g = e / f;
                 System.out.println("The answer is " + g + ".");
             }
             if(a.equals("+")) {
                 System.out.println("What is the first number?");
                 int h = sc.nextInt();
                 System.out.println("What is the second number?");
                 int i = sc.nextInt();
                 int j = h + i;
                 System.out.println("The answer is " + j + ".");
             }
             if(a.equals("-")) {
                 System.out.println("What is the first number?");
                 int k = sc.nextInt();
                 System.out.println("What is the second number?");
                 int l = sc.nextInt();
                 int m = k - /;
                 System.out.println("The answer is " + m + ".");
             }
                 System.out.println("Do you want solve another problem?");
                 String answer = tm.nextLine();
                 if(answer.equalsIgnoreCase("yes")) {
                       keepGoing = true;
                 }
                 else {
                     keepGoing = false;
                 }
            }
       }
 }

}

I don't know what to do to answer my question, so I've resorted to asking the internet. This is the only thing I can think of to solve my problem when the code runs and you answer yes to solve another question it errors just after it prints out the what kind of problem do you want to solve question again.

This is the error code: Exception in thread "main" java.util.NoSuchElementException: No line found at java.base/java.util.Scanner.nextLine(Scanner.java:1651) at Bruce.main(Bruce.java:11)

So that's what the error code, and I'm just assuming that my question is what I need to do. However, if I'm wrong please let me know.

Ryan_G
  • 1

0 Answers0