0% found this document useful (0 votes)
11 views

2

Uploaded by

LayanAlhosainy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

2

Uploaded by

LayanAlhosainy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

;import java.util.

Scanner

{ public class SimpleCalculator

{ public static void main(String[] args)

;Scanner input = new Scanner(System.in)

;System.out.print("Enter first number: ")

;)(double firstNumber = input.nextDouble

;System.out.print("Enter second number: ")

;)(double secondNumber = input.nextDouble

;System.out.println("Select an operation:")

;System.out.println("1. Add")

;System.out.println("2. Subtract")

;System.out.println("3. Multiply")

;System.out.println("4. Divide")

;)(int operation = input.nextInt

;double result

{ switch (operation)

:case 1

;result = firstNumber + secondNumber

;System.out.println("Result: " + result)

;break

:case 2

;result = firstNumber - secondNumber

;System.out.println("Result: " + result)


;break

:case 3

;result = firstNumber * secondNumber

;System.out.println("Result: " + result)

;break

:case 4

{ if (secondNumber != 0)

;result = firstNumber / secondNumber

;System.out.println("Result: " + result)

{ else }

;System.out.println("Error: Cannot divide by zero.")

}
;break

:default

;System.out.println("Invalid operation selected.")

;break

;)(input.close

}
}

You might also like