Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6733915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:49:37+00:00 2026-05-26T10:49:37+00:00

Possible Duplicate: In java, in this program it suddenly stops running properly at a

  • 0

Possible Duplicate:
In java, in this program it suddenly stops running properly at a certain point of code? but it compiles? any ideas what could be the issue?

import java.io.IOException;
import java.util.*;

public class task2 {
    public static void main (String [] args) throws IOException {
        int a;
        int b;
        String y;
        String x;
        Scanner input = new Scanner(System.in);

        System.out.println("Please enter number A:");
        a = input.nextInt();

        System.out.println("\nPlease enter number B:");
        b = input.nextInt();

        System.out.println("\nLastly, enter A if you wish it to be the dividor and/or subtractor, or if you wish it to be B, please enter B :");
        y=input.next();

        System.out.println("\nWhat would you like to do? Multiply (*), Divide (/), Subtract (-) or Add (+)? Please enter the symbol of which process you would like to have completed:");
        x=input.next();

        if (y.equals("b"+"B")) {
            if (x.equals("*")) {
                System.out.println("\nThe product of these numbers is:" + (a*b));}
            else if (x.equals("/")) {
                System.out.println("\nThe quotient of these numbers is:" + (a/b));}
            else if (x.equals("+")) {
                System.out.println("\nThe sum of these numbers is:" + (a+b));}
            else if (x.equals("-")) {
                System.out.println("\nThe difference of these numbers is:" + (a-b));
            }
        }

        else 
        if (y.equals("a"+"A")){
            if (x.equals("*")) {
                System.out.println("\nThe product of these numbers is:" + (b*a));}
            else if (x.equals("/")) {
                System.out.println("\nThe quotient of these numbers is:" + (b/a));}
            else if (x.equals("+")) {
                System.out.println("\nThe sum of these numbers is:" + (b+a));}
            else if (x.equals("-")) {
                System.out.println("\nThe difference of these numbers is:" + ((b-a)));
            }
        }
    }
}

A small program to do calculations on a set of two numbers. What I want is the user to enter the numbers and type of operation (including order) they want.
The result of the calculation does not display? any ideas? all help greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:49:38+00:00Added an answer on May 26, 2026 at 10:49 am

    You’re comparing y and x against A+a and B+b
    What you should do is :

    (y.equals("B") || y.equals("b"))

    Use the pipes || as an OR statement and not concatenating them with +

    Here’s the working code.

    import java.io.IOException;
    import java.util.Scanner;
    
        public class SOScrap {
        public static void main (String [] args) throws IOException {
        int a;
        int b;
        String y;
        String x;
        Scanner input = new Scanner(System.in);
    
        System.out.println("Please enter number A:");
        a = input.nextInt();
    
        System.out.println("\nPlease enter number B:");
        b = input.nextInt();
    
        System.out.println("\nLastly, enter A if you wish it to be the dividor and/or subtractor, or if you wish it to be B, please enter B :");
        y=input.next();
    
        System.out.println("\nWhat would you like to do? Multiply (*), Divide (/), Subtract (-) or Add (+)? Please enter the symbol of which process you would like to have completed:");
        x=input.next();
    
    
        if (y.equals("B") || y.equals("b")) {
    
        if (    x.equals("*")) {
        System.out.println("\nThe product of these numbers is:" + (a*b));}
        else
        if (x.equals("/")) {
        System.out.println("\nThe quotient of these numbers is:" + (a/b));}
        else
        if (x.equals("+")) {
        System.out.println("\nThe sum of these numbers is:" + (a+b));}
        else
        if (x.equals("-")) {
        System.out.println("\nThe difference of these numbers is:" + (a-b));}}
        else{
        if (y.equals("A") || y.equals("a")){
    
        if (x.equals("*")) {
        System.out.println("\nThe product of these numbers is:" + (b*a));}
        else
        if (x.equals("/")) {
        System.out.println("\nThe quotient of these numbers is:" + (b/a));}
        else
        if (x.equals("+")) {
        System.out.println("\nThe sum of these numbers is:" + (b+a));}
        else
        if (x.equals("-")) {
        System.out.println("\nThe difference of these numbers is:" + ((b-a)));}}}
               }}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Strange floating-point behaviour in a Java program I came across this weird
Possible Duplicate: java String concatenation How to Improve performance of this chunk of code
Possible Duplicate: Java REPL shell Hey, Is there any way to execute Java code
Possible Duplicate: Java floating point arithmetic What is special about this double math in
Possible Duplicate: Plugging in to Java compilers Edit - this appears to be a
Possible Duplicate: Java operator overload In c++, we can perform the operator overloading. But
Possible Duplicate: How can I convert my java program to an .exe file ?
Possible Duplicate: Clearest way to combine two lists into a map (Java)? Given this:
Possible Duplicate: What does this C++ code mean? I'm trying to map a C
Possible Duplicate: General strategy to resolve Java memory leak? I have a standalone program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.