At Westonci.ca, we connect you with the answers you need, thanks to our active and informed community. Discover the answers you need from a community of experts ready to help you with their knowledge and experience in various fields. Get detailed and accurate answers to your questions from a dedicated community of experts on our Q&A platform.

import java.util.scanner; import java.util.inputmismatchexception; public class powerresistorexcepthandling { public static void main(string[] args) { scanner scnr = new scanner(system.in); int currentlevel; int powerresistor; int resistorohms = 100; try { currentlevel = scnr.nextint(); powerresistor = currentlevel * currentlevel * resistorohms; system.out.println("power is " + powerresistor + "w"); } catch (inputmismatchexception excpt) { system.out.println("inputmismatchexception"); } } }

Sagot :

Inputmismatchexception: It is a class used for error handling in Java, it is imported with the line of code "import java.util.InputMismatchException;". The function of this exception class: Send an error message without interrupting the execution of the program when the user enters data that does not match the declared data type. For example, write letters instead of numbers as shown in the code below.

Java Code

import java.io.*;

import java.util.Scanner;

import java.util.InputMismatchException;

public class Main {

     public static void main(String[] args) {

       Scanner scnr = new Scanner(System.in);

       int currentlevel;

       int powerresistor;

       int resistorohms = 100;

       String ans;

 ans = "y";

 

 while (ans.equals("y")) {

     

     try {

         System.out.println("Enter number: ");

         currentlevel = scnr.nextInt();

                powerresistor = currentlevel * currentlevel * resistorohms;

                System.out.println("power is " + powerresistor + " w");

          ans = "y";

     }

           

           catch (InputMismatchException excpt) {

               System.out.println("error, inputmismatchexception");

                ans = "n";

 }

}

}

}

To learn more about Inputmismatchexception in Java see: https://brainly.com/question/18271188

#SPJ4

View image megatokay