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.
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
Thanks for using our platform. We're always here to provide accurate and up-to-date answers to all your queries. Thank you for choosing our platform. We're dedicated to providing the best answers for all your questions. Visit us again. Thank you for visiting Westonci.ca, your go-to source for reliable answers. Come back soon for more expert insights.