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
The ________ of the operating system enables the user to communicate with the computer system. Select one:
mojhsa [17]
The user interface (correct answer is a)
8 0
3 years ago
01000111 01110101 01100101 01110011 01110011 00100000 01110111 01101000 01100001 01110100 00111111
Natasha_Volkova [10]

12435 425 2 52 35 Guess what?

8 0
3 years ago
Fill the validateForm function to check that the phone number contains a number (use the isNaN function) and that the user name
Wittaler [7]

The answer & explanation for this question is given in the attachment below.

8 0
3 years ago
Which of these sedimentary rocks is made of the largest particles?
Marta_Voda [28]
Your answer is <span>A.conglomerate.

Hope this helps :)</span>
6 0
4 years ago
Amy, a project manager, needs to make a plan that ensures consistent delivery of the right message to the right people at the ri
AleksAgata [21]
I would have to say the answer is D.) A communication plan. Hope this helps! :-)
7 0
3 years ago
Other questions:
  • What is the part of the computer system that receives inputs, directs those inputs to the processor, and redirects the processed
    14·1 answer
  • Where would you go to cancel a print job?
    15·1 answer
  • 1. Assume that the vector monthSales of integers has already been declared and that its elements contain sales data for the 12 m
    11·1 answer
  • Find all three-digit numbers with non-zero first digit that are equal to the sum of the cubes of their digits.
    8·1 answer
  • What damage can a virus do to your computer?
    14·1 answer
  • What will be displayed after code corresponding to the following pseudocode is run? Main Set OldPrice = 100 Set SalePrice = 70 C
    10·1 answer
  • Who is your favorite smite god in Hi-Rez’s “Smite”
    14·1 answer
  • _____ selectors are used to select elements based on elements that are adjacent to them in the document hierarchy.
    9·1 answer
  • Anything a person writes or creates is __________
    6·2 answers
  • Define computer architecture?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!