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]
3 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]3 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
Five technology tools and their uses​
alexandr1967 [171]

Answer:

yeududfufjdjkakakkgmgmakaksjxh

6 0
3 years ago
Late at night, some traffic signals change patterns and become _____.
SCORPION-xisa [38]
The answer is B.

Late at night, some traffic signals change patterns and become flashing yellow or red lights.
4 0
3 years ago
Read 2 more answers
Reverse Word Order: Write a program that reverses the order of the words in a given sentence. This program requires reversing th
Lerok [7]

Answer:

The program in C++ is as follows:

#include <bits/stdc++.h>

using namespace std;

int main(){

string sentence,word="";

getline (cin, sentence);

vector<string> for_reverse;

for (int i = 0; i < sentence.length(); i++){

 if (sentence[i] == ' ')  {

  for_reverse.push_back(word);

  word = "";  }

 else{    word += sentence[i];}  }

for_reverse.push_back(word);

sentence="";

for (int i = for_reverse.size() - 1; i > 0; i--){

 sentence+=for_reverse[i]+" ";}

sentence+=for_reverse[0];

cout<<sentence<<endl;

return 0;

}

Explanation:

This declares sentence and word as strings; word is then initialized to an empty string

string sentence,word="";

This gets input for sentence

getline (cin, sentence);

This creates a string vector to reverse the input sentence

vector<string> for_reverse;

This iterates through the sentence

for (int i = 0; i < sentence.length(); i++){

This pushes each word of the sentence to the vector when space is encountered

<em>  if (sentence[i] == ' ')  { </em>

<em>   for_reverse.push_back(word);</em>

Initialize word to empty string

  word = "";  }

If the encountered character is not a blank space, the character is added to the current word

<em>  else{    word += sentence[i];}  } </em>

This pushes the last word to the vector

for_reverse.push_back(word);  

This initializes sentence to an empty string

sentence="";

This iterates through the vector

for (int i = for_reverse.size() - 1; i > 0; i--){

This generates the reversed sentence

 sentence+=for_reverse[i]+" ";}

This adds the first word to the end of the sentence

sentence+=for_reverse[0];

Print the sentence

cout<<sentence<<endl;

8 0
3 years ago
How to achieve competitive advantage using information systems models
Maurinko [17]

Information systems can achieve competitive advantage by engaging in:

  • Lowering costing.
  • Boasting differentiation of their product.
  • Changing Their competitive scope.

<h3>What is competitive advantage?</h3>

Competitive advantage is known to be that  factors that helps a firm to produce goods or services better or relatively more cheaply than their counterparts.

Note that in the case above, Information systems can achieve competitive advantage by engaging in:

  • Lowering costing.
  • Boasting differentiation of their product.
  • Changing Their competitive scope.

Learn more about competitive advantage from

brainly.com/question/14030554

#SPJ12

4 0
2 years ago
A powerful computer that acts as a hub for other computers is a called a ______.
zhannawk [14.2K]
It is called a server
7 0
3 years ago
Read 2 more answers
Other questions:
  • A weak fuel to air mixture along with normal airflow through a turbine engine may result in?
    8·1 answer
  • What are the advantages of a diverse workforce? Select all that apply.
    6·2 answers
  • Page _____ refers to whether a page is laid out vertically or horizontally.
    12·1 answer
  • Help!!!!!!!!!!!!!!!!!!!
    12·1 answer
  • List the various types of social media that have been covered in the tutorial. Mention the key purposes for which each media typ
    9·1 answer
  • Hardware consists of the physical devices associated with a computer system, where software is the set of instructions the hardw
    13·1 answer
  • You wish to use a file system that creates a record or log of to-be-committed changes in the system so that if the system crashe
    14·1 answer
  • Meaning of sperm count
    5·2 answers
  • What do macOS and Windows use to prevent us from accidentally deleting files?
    15·1 answer
  • Fill in the missing terms relating to computer software
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!