Write a Java program that will accept two float numbers and an operator (+-*) then the program will print out the result of the specified expression based on the inputted operator.
The user interface may be:
Input the number 1: 4
Input the number 2: 5
Input the operator: +
The result of 4+5=9
Step by step workshop instructions:
In the project above, you create a new class named "Part2.java" and add the code:
import java.util.Scanner;
public class Part2 {
public static void main(String[] args) {
float num1, num2;
String op;
Scanner sc = new Scanner(System.in);
System.out.println("Input the number 1:");
num1 = sc.nextFloat();
System.out.println("Input the number 2:");
num2 = sc.nextFloat();
System.out.println("Input the operator(+-*/):");
sc = new Scanner(System.in);
op = sc.nextLine();
if (op.equals("+")) {
System.out.println("The result of " + num1 + op + num2 + " = " + (num1 + num2));
}
}
}
You must add your code to get the result when the user inputs another operator.