1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
padilas [110]
2 years ago
11

The Double.parseDouble() method requires a String argument, but it fails if the String cannot be converted to a floating-point n

umber. Write an application in which you try accepting a double input from a user and catch a NumberFormatException if one is thrown. The catch block forces the number to 0 and displays Value entered cannot be converted to a floating-point number. Following the catch block, display the number.
Computers and Technology
1 answer:
Andrei [34K]2 years ago
3 0

Answer:

  1. import java.util.Scanner;
  2. public class Main {
  3.    public static void main(String[] args) {
  4.        Scanner input = new Scanner(System.in);
  5.        String numStr = input.nextLine();
  6.        double num;
  7.        try{
  8.            num = Double.parseDouble(numStr);
  9.        }
  10.        catch(NumberFormatException e){
  11.            num = 0;
  12.            System.out.println("Value entered cannot be converted to a floating point number.");
  13.        }
  14.    }
  15. }

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).  

You might be interested in
PLEASE HELP ME ASAP!!! Looking at the misty rain and fog (pictured above) Explain at least two defensive driving techniques you
JulsSmile [24]
1.Slow down 2. Break earlier
7 0
3 years ago
Write a program in C++ to implement bubblesort using the swap function ?
marishachu [46]

C++ program for implementation of Bubble sort  

#include <bits/stdc++.h>  

using namespace std;  

 void swap(int *x, int *y)  /*Defining Swap function of void return type*/

{  

  int temp = *x;  //Swaping the values  

   *x = *y;  

   *y = temp;  

}  

void bubbleSort(int array[], int n) /*Defining function to implement bubbleSort  */

{  

  int i, j;  

  for (i = 0; i < n-1; i++)      

      for (j = 0; j < n-i-1; j++)  /*The last i components are already in location  */

      if (array[j] > array[j+1])  

          swap(&array[j], &array[j+1]);  //Calling swap function

}  

int main()  //driver function

{  

   int array[] = {3, 16, 7, 2, 56, 67, 8}; //Input array  

   int n = sizeof(array)/sizeof(array[0]);  //Finding size of array

   bubbleSort(array, n); //Function calling  

   cout<<"Sorted array: \n";  

   for (int i = 0; i < n; i++)  //printing the sorted array

       cout << array[i] << " ";  

   cout << endl;  

 return 0;  

}  

<u>Output</u>

Sorted array:  

2 3 7 8 16 56 67

3 0
3 years ago
A compound boolean expression created with the ___ operator is true only if all its connected expressions are true.
kiruha [24]
The answer to this is OR..I think..Hope i helped
4 0
2 years ago
Explain the different types of computer software programs. Be specific and use examples.
lorasvet [3.4K]

Answer: well there are many types of software out there and let's use Microsoft for an example there a really protective company so more people would want to buy from Microsoft they have a lot of high-tech computers so and I'm not favoriting Microsoft it's just what I've use Chrome also is really good but you would kind of want to go off like reviews that you see and everything like that because I'm not a big computer tech but that's just what I know

Explanation:

3 0
3 years ago
Windows administration allows a certain level of access for a file or folder to be assigned to a(n) ____________________ rather
soldi70 [24.7K]

Answer:

Group

Explanation:

A folder assigned to a single user can only be accessed by a single person, to get many users access a folder windows administrator shares a folder to a workgroup. using the simple steps below.

Login as the admin of the system, Right-click on the folder you want to give permission on, after clicking on properties, click on security, add user or group after clicking the edit. and your folder is shared to a group and all users in the group have access to it.

6 0
3 years ago
Other questions:
  • What software that allow for one-click performance profiles for msi video card??
    5·1 answer
  • Your new client's AdWords account has one campaign with one ad group that contains a list of hundreds of keywords. Which best pr
    6·1 answer
  • What is contrast (in Photography)?
    14·1 answer
  • Which of the following are benefits of designing a scalable system? Choose 3 options.
    15·1 answer
  • Write a program that prints the following 45 pairs of numbers:
    8·1 answer
  • Decrypt this message: P ht uva h zwf
    13·1 answer
  • 1.
    9·1 answer
  • NEED HELP ASAP!!!!!!
    7·2 answers
  • You have been elected to assist the school's yearbook committee and newspaper club in purchasing new computers. The current comp
    10·1 answer
  • In “Plugged In,” the author’s purpose is to persuade. Which of the following quotes from the text shows that the author’s purpos
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!