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
andreev551 [17]
3 years ago
6

2. Using the Enhanced for Statement, write an application that uses an enhanced for statement to sum the double values passed by

the command-line arguments. [Hint: Use the static method parseDouble of class Double to convert a String to a double value.] This is sample run of your program: The·sum·of·the·double·values·passed·in·from·the·command·line·is·0.0↵

Computers and Technology
1 answer:
solniwko [45]3 years ago
5 0

Answer:

Here is the program:

public class DoubleValue

{ public static void main(String[] args) { //start of the main function

 double sum = 0.0;  // initialize double type sum by 0.0

//for statement to sum the double values passed by the command-line //arguments

       for (String str : args)        {  

         sum += Double.parseDouble(str);  

//returns double representation of the passed str argument and takes the //sum of these double values         }

       System.out.printf("The sum of the double values passed in from the command line is %.1f\n", sum);  }  }      

//prints the above message with output 0.0                                  

Explanation:

The above program has a static method parseDouble of class Double to convert a string str to a double value and the for statement is used to sum the double values passed by command line arguments. This sum is stored in sum variable and is displayed in the output. The program along with its output is attached.

If you want to get the input from the user you can use the following code. Just use the Scanner class to take input from the user.

import java.util.Scanner;

public class DoubleValue

{ public static void main(String[] args) {

//two string type variables

 String str1;

               String str2;

//scans and reads input from user

Scanner input = new Scanner(System.in);

System.out.println("Enter value of str1: ");

str1 = input.next();

System.out.println("Enter value of str2: ");

str2 = input.next();

double sum = 0.0;

//sum double values and parseDouble function is used to convert string to //double value

sum += Double.parseDouble(str1) + Double.parseDouble(str2);

System.out.printf("The sum of the double values passed in from the command line is %.1f\n", sum); } }  //prints result of the sum

You might be interested in
30 POINTS! PLEASE ANSWER QUICK!!!
SpyIntel [72]

Answer:

your doctype comes first.

Explanation:

The first thing you should make sure to have in any HTML document you create is a "document type definition (DTD)" declaration.

it defines what elements and attributes are allowed to be used in a certain flavor of HTML

6 0
3 years ago
Victoria is working on a computer that was infected with a virus when a client clicked on a link and downloaded a Trojan. Victor
tangare [24]

Answer:

The question is incomplete and should read as follows:

Victoria is working on a computer that was infected with a virus when a client clicked on a link and downloaded a Trojan. Victoria researched the virus and learned that the virus might have written itself into System Restore. What does Victoria need to do to run the antivirus software on System Restore?

This issue can be fixed by taking the following steps:

A. Disable System Protection.

B. Back up the restore point.

C. Enable System Protection.

D. Run the antivirus software on a restore point.

The system is then restored to the now clean restore point to rid the computer completely of the virus.

Explanation:

3 0
3 years ago
Read 2 more answers
Can someone help me with these questions on linear dimensions pls
andrew-mc [135]
Size dimentions reffer to overall dimentions and will tell the overall width, lenth height and depth of something location dimentions means the locatuon of each geometric shape.
7 0
3 years ago
Read 2 more answers
Test if a number grade is an A (greater than or equal to 90). If so, print "Great!". Sample Run Enter a Number: 98 Sample Output
Debora [2.8K]

Answer:

Using Python language :

a = eval ( input ( "Enter a mark please"))

if ( a <0){

print ("Invalid mark")};

else if (a >=90 && a <=100){ print

( "GREAT")};

Explanation:

7 0
3 years ago
Help! Will add the brainliest.
geniusboy [140]

Answer:

b

Explanation:

8 0
3 years ago
Read 2 more answers
Other questions:
  • Write a literal representing the false value in c++.
    11·1 answer
  • On an Ethernet, a ____ is broadcast to every device but is accepted only by the device to which it is addressed.
    5·1 answer
  • In order to delete an object, it must be?
    14·1 answer
  • para que sirve los siguientes sistemas operativos : a. Windows 10 b. Apple yosemite c. linux Ubuntu d. Android marshmallow e. IO
    9·1 answer
  • What is the result when you run the following program?<br> print("2 + 7')<br> print(3 + 1)
    6·2 answers
  • Click print to publish your post in a blog true or false.​
    5·2 answers
  • Write features of Fifth Generation of computer?​
    12·2 answers
  • how does the use of data abstraction manage complexity in program code? how does using lists make a program easier to develop an
    5·1 answer
  • To use Aggregate functions on subgroups within the total result set, place the Aggregate function in the Select clause and add t
    7·1 answer
  • Which method can be used for making a robot perform a different set of functions?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!