66 840
Assignments Done
99,1%
Successfully Done
In October 2018

Answer to Question #3923 in Java | JSP | JSF for Sally

Question #3923
import java.util.Scanner;

public class NetbeanTest{
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
System.out.print("Enter Operator (+,-,*,/): ");
String plan = console.nextLine();
System.out.print("Enter Value 1: ");
int num1 = console.nextInt();
System.out.print("Enter Value 2: ");
int num2 = console.nextInt();
int result;

if (plan.equals(" + ")) result = num1 + num2; {
System.out.println("Result of " + num1 + " + " + num2 + " = " + result);}
if (plan.equals(" - ")) result = num1 - num2; {
System.out.println("Result of " + num1 + " - " + num2 + " = " + result);}
if (plan.equals(" * ")) result = num1 * num2; {
System.out.println("Result of " + num1 + " * " + num2 + " = " + result); }
if (plan.equals(" / ")) result = num1 / num2; {
System.out.println("Result of " + num1 + " / " + num2 + " = " + result);}
}}
// What went wrong?//
Expert's answer
Correct variant:

import java.util.Scanner;public class question123 {

public static void main(String[] args) {
Scanner console = new Scanner(System.in);
System.out.print("Enter Operator (+,-,*,/): ");
String plan = console.nextLine();
System.out.print("Enter Value 1: ");
int num1 = console.nextInt();
System.out.print("Enter Value 2: ");
int num2 = console.nextInt();
int result;
if (plan.equals("+"))
{
result = num1 + num2;
System.out.println("Result of " + num1 + " + " + num2 + " = "
+ result);
}
if (plan.equals("-"))
{
result = num1 - num2;
System.out.println("Result of " + num1 + " - " + num2 + " = " +
result);
}
if (plan.equals("*"))
{
result = num1 * num2;
System.out.println("Result of " + num1 + " * " + num2 + " = " +
result);
}
if (plan.equals("/"))
{
result = num1 / num2;
System.out.println("Result of " + num1 + " / " + num2 + " = " +
result);
}
}

}

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

Assignment Expert
10.08.11, 11:53

You are welcome!

Sally
10.08.11, 06:44

Thanks alot.

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions