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
lara31 [8.8K]
3 years ago
7

Write a program that asks the user to input a set of floating-point values. When the user enters a value that is not a number, g

ive the user a second chance to enter the value. After two chances, quit reading input. Add all correctly specified values and print the sum when the user is done entering data. Use exception handling to detect improper inputs.
Computers and Technology
2 answers:
forsale [732]3 years ago
4 0

Answer:

See Explaination for program code

Explanation:

Code below

import java.io.*;

import java.util.*;

// Declare a class

public class DataReader

{

// Start the main method.

public static void main(String[] args)

{

// create the object of scanner class.

Scanner scan = new Scanner(System.in);

// Declare variables.

boolean done = false;

boolean done1 = false;

float sum = 0;

double v;

int count = 0;

// start the while loop

while (!done1)

{

// start the do while loop

do

{

// prompt the user to enter the value.

System.out.println("Value:");

// start the try block

try

{

// input number

v = scan.nextDouble();

// calculate the sum

sum = (float) (sum + v);

}

// start the catch block

catch (Exception nfe)

{

// input a character variable(\n)

String ch = scan.nextLine();

// display the statement.

System.out.println(

"Input Error. Try again.");

// count the value.

count++;

break;

}

}

// end do while loop

while (!done);

// Check whether the value of count

// greater than 2 or not.

if (count >= 2)

{

// display the statement on console.

System.out.println("Sum: " + sum);

done1 = true;

}

}

}

}

Lady_Fox [76]3 years ago
3 0

Answer:

Check the explanation

Explanation:

// include the necessary packages

import java.io.*;

import java.util.*;

// Declare a class

public class DataReader

{

// Start the main method.

public static void main(String[] args)

{

// create the object of scanner class.

Scanner scan = new Scanner(System.in);

// Declare variables.

boolean done = false;

boolean done1 = false;

float sum = 0;

double v;

int count = 0;

// start the while loop

while (!done1)

{

// start the do while loop

do

{

// prompt the user to enter the value.

System.out.println("Value:");

// start the try block

try

{

// input number

v = scan.nextDouble();

// calculate the sum

sum = (float) (sum + v);

}

// start the catch block

catch (Exception nfe)

{

// input a character variable(\n)

String ch = scan.nextLine();

// display the statement.

System.out.println(

"Input Error. Try again.");

// count the value.

count++;

break;

}

}

// end do while loop

while (!done);

// Check whether the value of count

// greater than 2 or not.

if (count >= 2)

{

// display the statement on console.

System.out.println("Sum: " + sum);

done1 = true;

}

}

}

}

Sample Output:

Value:

12

Value:

12

Value:

ten

Input Error. Try again.

Value:

5

Value:

nine

Input Error. Try again.

Sum: 29.0

You might be interested in
What command utilizes the limpel-ziv (lz77) compression algorithm and achieves a compression ratio of 60-70 percent?
AURORKA [14]

The limpel-ziv (lz77) compression technique is used by the GNU zip (gzip) tool to produce a compression ratio of 60–70%.

<h3>How do methods for data compression function? Describe the LZW algorithm.</h3>

Compression methods lower the amount of memory needed to hold pictures and the number of bytes needed to represent data. Compression improves the amount of data that can be delivered over the internet and enables the storage of more photos on a given media.

Abraham Lempel, Jacob Ziv, and Terry Welch developed the table-based lookup technique known as LZW compression to compress a file into a smaller file. The TIFF image format and the GIF image format are two frequently used file formats that employ LZW compression.

To know more about limpel-ziv (lz77) compression algorithm, Visit:

<u>brainly.com/question/19878993</u>

#SPJ4

4 0
1 year ago
You are creating a story map about Mexico. After configuring the web app template, you launch the app to test it. When the app o
navik [9.2K]
Nbdjsksjsidjdjwkwejd
3 0
3 years ago
-1
N76 [4]

Answer:A flowchart is a diagram that depicts the steps involved in solving a problem. The following flowchart shows how to output the multiplication table ( n * 1 to m * 1) of a number, n and m:

3 0
3 years ago
Question 1 :George, a user, is having trouble connecting to network resources, including shared folders on the local network and
vazorg [7]

Complete Question:

George, a user, is having trouble connecting to network resources, including shared folders on the local network and Internet resources. Yesterday he was able to connect with no problems. You need to ensure that he can connect to these resources. Which tool should you use FIRST?

Group of answer choices

A. ipconfig

B. Device Manager

C. My Network Places

D. Control Panel

Answer:

A. ipconfig

Explanation:

As a network administrator, to ensure that George can connect to the network resources, shared folders, and internet resources, the tool you should use first is the "ipconfig" in the command line. This is a troubleshooting process that would help to identify the problem and to establish a theory of probable cause.

<em>Since George could connect the previous day without any problem, it is most likely that the TCP/IP settings has been altered. Therefore, to view this settings you'll have to use an ipconfig command. </em>

4 0
3 years ago
Namespaces cannot have namespaces as members.<br><br> True<br><br> False
Anna71 [15]

Answer:

False

Explanation:

namespaces can be nested. That is we can have a hierarchy of namespaces.

For examples suppose we have a namespace top. Within this we have another namespace first. At the next level we have a namespace called second. Then we have a class MyClass as a member of this namespace second. Then the complete description of the class will be as follows:

top::first::second::MyClass

5 0
3 years ago
Other questions:
  • Several days a week, usually between 8:00 a.m. and 9:00 a.m., users complain of MWI problems. Some have new messages, but their
    11·1 answer
  • What ipconfig command line option can be used to delete cached dns information from memory?​?
    9·1 answer
  • Molly, an end-user, connects an external monitor, external keyboard and mouse, and a wired network cable to her laptop while wor
    5·2 answers
  • Which method do software testers use to isolate new code from the rest of the network during the test stage of the software deve
    15·1 answer
  • What is another term for accountability?
    7·2 answers
  • Hank is the network administrator responsible for managing the web server cluster for an e-commerce company. He’s worried about
    9·1 answer
  • A barcode is a Select one: a. coded instruction needed to control computer hardware. b. confidential computer code required by H
    7·1 answer
  • Please help I really need it :(
    12·1 answer
  • What is the correct way to write h1 tag
    12·1 answer
  • drag each type of document to the correct location on the table. Drag each document to its respective category
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!