Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an assembler program that asks the user (as shown below) for two integers

ID: 3937475 • Letter: W

Question

Write an assembler program that asks the user (as shown below) for two integers and a single character representing the arithmetic operations: addition, subtraction, multiplication and integer division (displays both quotient and remainder). Perform the requested operation on the operands and display the result as specified below. Assume SIGNED NUMBERS. The program should not divide by 0! If the user attempts to divide by 0, display the error message: "Cannot divide by zero." If this error occurs, the program should not display "The result of..." message. The character representing the operation must be one of these: + - */The text output of the program should look exactly like this example: (the user input will change) Enter first integer: 5 Enter operator:/Enter second integer: 7 The result of 5/7 is 0 and the remainder is 5 OR Enter first integer: 8 Enter operator:/Enter second integer: 0 Cannot divide by zero.

Explanation / Answer

import java.util.*;
public class Assembler {
   public static void main(String a[]){
       Scanner sc=new Scanner(System.in);
       System.out.println("Enter the first number");
      
       int num1=sc.nextInt();
       System.out.println("Enter Operator");
       String str=sc.next();
       System.out.println("Enter the second number");
       int num2=sc.nextInt();
       if(str.equals("*")){
           System.out.println(num1*num2);
       }
       else if(str.equals("/")){
           if(num2>0){
               System.out.println(num1/num2);
           }
           else
               System.out.println("Cannot divide by zero");
       }
       else if(str.equals("+")){
           System.out.println(num1+num2);
       }
       else if(str.equals("-")){
           System.out.println(num1-num2);
       }
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote