Computer Science, asked by abhiaekhdutta98, 1 month ago

please write a variable description table for this following program please answer it correctly exams nearby.
Programiz

Search Programiz
Java Program to Make a Simple Calculator Using switch...case
In this program, you'll learn to make a simple calculator using switch..case in Java. This calculator would be able to add, subtract, multiply and divide two numbers.


To understand this example, you should have the knowledge of the following Java programming topics:

Java switch Statement
Java Scanner Class
Example: Simple Calculator using switch Statement
import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner reader = new Scanner(System.in);
System.out.print("Enter two numbers: ");

// nextDouble() reads the next double from the keyboard
double first = reader.nextDouble();
double second = reader.nextDouble();

System.out.print("Enter an operator (+, -, *, /): ");
char operator = reader.next().charAt(0);

double result;

switch (operator) {
case '+':
result = first + second;
break;

case '-':
result = first - second;
break;

case '*':
result = first * second;
break;

case '/':
result = first / second;
break;

// operator doesn't match any case constant (+, -, *, /)
default:
System.out.printf("Error! operator is not correct");
return;
}

System.out.println(first + " " + operator + " " + second + " = " + result);
}
}

Answers

Answered by 2602alpha
0

Answer:

Explanation:

please write a variable description table for this following program please answer it correctly exams nearby.

Programiz

Search Programiz

Java Program to Make a Simple Calculator Using switch...case

In this program, you'll learn to make a simple calculator using switch..case in Java. This calculator would be able to add, subtract, multiply and divide two numbers.

To understand this example, you should have the knowledge of the following Java programming topics:

Java switch Statement

Java Scanner Class

Example: Simple Calculator using switch Statement

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner reader = new Scanner(System.in);

System.out.print("Enter two numbers: ");

// nextDouble() reads the next double from the keyboard

double first = reader.nextDouble();

double second = reader.nextDouble();

System.out.print("Enter an operator (+, -, *, /): ");

char operator = reader.next().charAt(0);

double result;

switch (operator) {

case '+':

result = first + second;

break;

case '-':

result = first - second;

break;

case '*':

result = first * second;

break;

case '/':

result = first / second;

break;

// operator doesn't match any case constant (+, -, *, /)

default:

System.out.printf("Error! operator is not correct");

return;

}

System.out.println(first + " " + operator + " " + second + " = " + result);

}

}

Answered by ltzSweetAngel
0

Java Program to Check if a Given Integer is Odd or Even

public class Odd_Even.

int n;

Scanner s = new Scanner(System.

System. out. print("Enter the number you want to check:");

n = s. nextInt();

if(n % 2 == 0)

System. out. println("The given number

"+n+" is Even ");

System. out. println("The given number "+n+" is Odd ");

Please make me as brainlist ♫ ♫ ☆ ☃️ ☆ ♫

Similar questions