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

Write a Java application that asks a user to enter two integers (A and B) and th

ID: 3552342 • Letter: W

Question

  1. Write a Java application that asks a user to enter two integers (A and B) and then display the results of A/B. Catch any division by zero errors and prompt the user to reenter the value of B. Be sure your code compiles and runs as expected. Name your Java file Yournamehw2a.java.
  2. Write a Java interface named Searchable with two abstract methods: one named Way2Search that returns a String and another named MaxTime that returns an Integer. Be sure your code compiles and runs as expected. Name your Java file Searchable.java.

Explanation / Answer

package com.Project.com.Project.Chegg;


import java.util.Scanner;


public class Yournamehw2a {


public static void main(String[] args) {

// TODO Auto-generated method stub

while(true){ // TO re-prompt the user to enter the valid values

System.out.println("Please enter the two integers"); //to get the user inputs

Scanner Sc = new Scanner(System.in);

int A = Sc.nextInt();

int B = Sc.nextInt();

try{ //try block actual calculation

System.out.println(A/B);

break; // to break from the while loop if there is no exception

}

catch(ArithmeticException e){ //catch block to handle exception

System.out.println("Invalid operation :" + e.getMessage());//print the message

}

}

}


}

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