Java program----------
Answers
Answer:
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter 2 numbers-");
int a = sc.nextInt();
int b = sc.nextInt();
System.out.print("Choose operation letter:");
char c = sc.next().charAt(0);
if(c == 'D' || c == 'd'){
System.out.println(a + " / " + b + " = " + (a/(float)b));
}
else if(c == 'A' || c == 'a'){
System.out.println(a + " + " + b + " = " + (a+b));
}
else if(c == 'M' || c == 'm'){
System.out.println(a + " * " + b + " = " + (a*b));
}
else if(c == 'S' || c == 's'){
System.out.println(a + " - " + b + " = " + (a-b));
}
else if(c == 'R' || c == 'r'){
System.out.println(a + " % " + b + " = " + (a%b));
}
else if(c == 'E' || c == 'e'){
System.out.println("exiting....");
}
else{
System.out.println("Invalid letter for operation");
}
}
}
Explanation:
Answer:
Answer:
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter 2 numbers-");
int a = sc.nextInt();
int b = sc.nextInt();
System.out.print("Choose operation letter:");
char c = sc.next().charAt(0);
if(c == 'D' || c == 'd'){
System.out.println(a + " / " + b + " = " + (a/(float)b));
}
else if(c == 'A' || c == 'a'){
System.out.println(a + " + " + b + " = " + (a+b));
}
else if(c == 'M' || c == 'm'){
System.out.println(a + " * " + b + " = " + (a*b));
}
else if(c == 'S' || c == 's'){
System.out.println(a + " - " + b + " = " + (a-b));
}
else if(c == 'R' || c == 'r'){
System.out.println(a + " % " + b + " = " + (a%b));
}
else if(c == 'E' || c == 'e'){
System.out.println("exiting....");
}
else{
System.out.println("Invalid letter for operation");
}
}
}
Explanation:
Explanation: