Question

In Java in main do the following: Create four double variables. Give them any name you...

In Java in main do the following:

  1. Create four double variables. Give them any name you feel is appropriate.
  2. Output a prompt that asks for the input of four doubles values.
  3. Fill the variables you created with values from the keyboard

Once you have completed the above output the following:

  1. The square of each number
  2. The sum of the squares
  3. The average of the squares
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program :

import java.util.*;
public class Main
{
   public static void main(String[] args) {
   Scanner s = new Scanner(System.in);
   double n1,n2,n3,n4,s1,s2,s3,s4,sum;
   System.out.print("Enter first value:");
   n1=s.nextInt();
   System.out.print("Enter second value:");
   n2=s.nextInt();
   System.out.print("Enter third value:");
   n3=s.nextInt();
   System.out.print("Enter fourth value:");
   n4=s.nextInt();
   s1=n1*n1;
   s2=n2*n2;
   s3=n3*n3;
   s4=n4*n4;
   sum=s1+s2+s3+s4;
   System.out.println("\nThe square of the "+n1+" is "+ s1);
   System.out.println("The square of the "+n2+" is "+ s2);
   System.out.println("The square of the "+n3+" is "+ s3);
   System.out.println("The square of the "+n4+" is "+ s4);
   System.out.println("\nThe sum of the squares :"+ sum);
   System.out.println("\nThe average of the squares :"+sum/4);
}

}

Screenshot of the program:

Output:

Add a comment
Know the answer?
Add Answer to:
In Java in main do the following: Create four double variables. Give them any name you...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use C Create a function that will take in a vector (three double variables) representing a...

    Use C Create a function that will take in a vector (three double variables) representing a position in meters. Calculate the magnitude of the vector in meters: sqrt(x * x + y * y + z * z) Calculate the magnitude of the vector in feet: magnitudeInMeters * 3.28084 Using passing by reference, return both outputs from the same function. Input: Three unique doubles, each one representing a component of the vector. Output: Magnitude of the vector in meters, magnitude...

  • create a new Java application called "WeightedAvgWithExceptions" (without the quotation marks), according to the following guidelines...

    create a new Java application called "WeightedAvgWithExceptions" (without the quotation marks), according to the following guidelines and using try-catch-finally blocks in your methods that read from a file and write to a file, as in the examples in the lesson notes for reading and writing text files. Input File The input file - which you need to create and prompt the user for the name of - should be called 'data.txt', and it should be created according to the instructions...

  • This code is in java. Create a Java class that has the private double data of length, width, and price. Create the gets...

    This code is in java. Create a Java class that has the private double data of length, width, and price. Create the gets and sets methods for the variables. Create a No-Arg constructor and a constructor that accepts all three values. At the end of the class add a main method that accepts variables from the user as input to represent the length and width of a room in feet and the price of carpeting per square foot in dollars...

  • This is for a java program public class Calculation {    public static void main(String[] args)...

    This is for a java program public class Calculation {    public static void main(String[] args) { int num; // the number to calculate the sum of squares double x; // the variable of height double v; // the variable of velocity double t; // the variable of time System.out.println("**************************"); System.out.println(" Task 1: Sum of Squares"); System.out.println("**************************"); //Step 1: Create a Scanner object    //Task 1. Write your code here //Print the prompt and ask the user to enter an...

  • in java : Create Java Application you are to create a project using our designated IDE...

    in java : Create Java Application you are to create a project using our designated IDE (which you must download to your laptop). Create the code to fulfill the requirements below. Demonstrate as stipulated below. Create a Main Application Class called AddressBookApplication (a counsole application / command line application). It should Contain a Class called Menu that contains the following methods which print out to standard output a corresponding prompt asking for related information which will be used to update...

  • Write a simple Java program with the following naming structure: Open Eclipse Create a workspace called...

    Write a simple Java program with the following naming structure: Open Eclipse Create a workspace called hw1 Create a project called hw1 (make sure you select the “Use project folder as root for sources and class files”) Create a class called Hw1 in the hw1 package (make sure you check the box that auto creates the main method). Add a comment to the main that includes your name Write code that demonstrates the use of each of the following basic...

  • Programming assignment for Java: Do not add any other instance variables to any class, but you...

    Programming assignment for Java: Do not add any other instance variables to any class, but you can create local variables in a method to accomplish tasks. Do not create any methods other than the ones listed below. Step 1 Develop the following class: Class Name: College Degree Access Modifier: public Instance variables Name: major Access modifier: private Data type: String Name: numberOfCourses Access modifier: private Data type: int Name: courseNameArray Access modifier: private Data type: String Name: courseCreditArray Access modifier:...

  • package _solution; /** This program demonstrates how numeric types and operators behave in Java Do Task...

    package _solution; /** This program demonstrates how numeric types and operators behave in Java Do Task #1 before adding Task#2 where indicated. */ public class NumericTypesOriginal { public static void main (String [] args) { //TASK #2 Create a Scanner object here //identifier declarations final int NUMBER = 2 ; // number of scores int score1 = 100; // first test score int score2 = 95; // second test score final int BOILING_IN_F = 212; // boiling temperature double fToC;...

  • Problem H1 (Using C++) In the main function, define four variables of type int, named: first,...

    Problem H1 (Using C++) In the main function, define four variables of type int, named: first, second, third, and total. Write a function named getData that asks the user to input three integers and stores them in the variables first, second, and third which are in the main function. Write a function named computeTotal that computes and returns the total of three integers. Write a function named printAll that prints all the values in the format shown in the following...

  • Java 1. Create an application named NumbersDemo whose main() method holds two integer variables. Assign values...

    Java 1. Create an application named NumbersDemo whose main() method holds two integer variables. Assign values to the variables. In turn, pass each value to methods named displayTwiceTheNumber(), displayNumberPlusFive(), and displayNumberSquared(). Create each method to perform the task its name implies. 2. Modify the NumbersDemo class to accept the values of the two integers from a user at the keyboard. This is the base code given: public class NumbersDemo { public static void main (String args[]) { // Write your...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT