Answer:
- import java.util.Scanner;
-
- public class Main {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- String numStr = input.nextLine();
- double num;
- try{
- num = Double.parseDouble(numStr);
- }
- catch(NumberFormatException e){
- num = 0;
- System.out.println("Value entered cannot be converted to a floating point number.");
- }
- }
- }
Explanation:
The solution code is written in Java.
Firstly, we create a Scanner object and prompt user to input a number (Line 5-6). Next, we create a try -catch block and place the parseDouble inside the try block. If the input is invalid (e.g. "abc"), a NumberFormatException error will be thrown and captured and set the num to 0 and display the error message (Line 11 - 13).
Answer:
A computer is an electronic device that manipulates information, or data. It has the ability to store, retrieve, and process data. You may already know that you can use a computer to type documents, send email, play games, and browse the Web.
The answer is b. because A is using one at a time. C is trying to use 1 at a time.
The answer is true.
Explanation:
The scanner class's methods are the methods in java.util, which allows the user to read values of various types. If the nextLine is issued after a numeric read and the numeric value is at the end of the line, nextLine returns the empty string.
The problem occurs when you click the enter key which is a new line \n character. nextInt() has only the integer but skips the new line \n.
To solve this problem, you have to add the input.nextLine() after reading the int it will consume the \n.
Hence, make input.nextLine(); call after input.nextint(); which reads till end of life.
Answer: The memory card
Explanation: If it is broken then you might lose all your data. AND I SAID MIGHT