create and use an array variable in a java program

create and use an array variable in a java program

how do i write a program that will prompt the user for a list of 5 prices, once the user has entered all values , your program should compute and display the following: The sum of all the prices, The average of the prices, All prices that higher than the calculated average

View Answers

March 8, 2011 at 2:40 PM

import java.util.*;
class Price{
    public static void main(String[] args) 
    {
        Scanner input=new Scanner(System.in);
        System.out.println("Enter prices: ");
        double prices[]=new double[5];
        int sum=0;
        for(int i=0;i<prices.length;i++){
            prices[i]=input.nextDouble();
        }
        for(int i=0;i<prices.length;i++){
        sum+=prices[i];
        }
        System.out.println("Sum of all prices: "+sum);
        double average=sum/prices.length;
        System.out.println("Average of all prices: "+average);
        System.out.println("Prices that are larger than the average: ");
        for(int i=0;i<prices.length;i++){
            if(prices[i]>average){
                System.out.println(prices[i]);
            }
        }
    }
}

Ads









Related Tutorials/Questions & Answers:
create and use an array variable in a java program
create and use an array variable in a java program  how do i write a program that will prompt the user for a list of 5 prices, once the user has entered all values , your program should compute and display the following: The sum
array variable in a java program
array variable in a java program  How do i write a program that will prompt the user for a list of 5 prices, that cosist of the sum of all the prices, the average of the prices, and all prices that are higher than the calculated
Advertisements
How to create and use Array in Java?
How to create and use Array in Java?  Hi, How to create and use Array in Java? Write program to construct and use the array. Thanks   Hi... can read complete example at Array in Java. Thanks
java program based on array
java program based on array  write a program to create an array of 10 integers in main.accept values from the user in that array .now again ask the use another nomber and pass the array and the no. entered to function called
java program based on array
java program based on array  Create Student class with attributes - marks, name, gender, email with appropriate data types. Create another class StudentDemo which will have main method. Declare array of Student object with size
Create list from array in Java
Create list from array in Java  Hi, I have an array with some data. How to Create list from array in Java? Thanks   Hi, Here is example of creating of creating an array: String[] names = new String[]{"Java", "JSP
Java create new array of strings.
Java create new array of strings.  Java create new array of strings...); } } } Description: Array is container which holds fix length of any kind of data type...] name is an String type array can hold 7 values. You can also
JSP Create Variable
from 'JSP Create Variable'. To understand the example we create an array... JSP Create Variable          JSP Create Variable is used to create
array program
array program  write a java program which will take 10 elements as command line arguments and count how many times 3 occurs in array
Create Array ??
Create Array ??   Question in e-clips program: Part 1. Array... stores list of ‚??PhoneEntry‚?? objects. Use an array of size (MAXSIZE = 1000...?¶ . -Create an appropriate interface that use the class ‚??MyLinkedList‚
How to create variable in TensorFlow?
variable, you have to create the TensorFlow variable to use it with TensorFlow graph. Then tf.variable() method is used to create variable in TensorFlow...How to create variable in TensorFlow?  Hi, How to create variable
Create Session Variable PHP
Create Session Variable PHP  hi, Write a program which shows the example of how to create session variable in PHP. Please suggest the reference links. Thanks,   Hi, Here is the example that explain how to create
How to create first program in Java?
How to create first program in Java?  Hi, I am new in Java programming. Tell me How to create first program in Java? Thanks   Hi, Read more at First Java Program. Thanks
How to create first Java Program?
How to create first Java Program?  Hi, I am beginner and I want to write first Java program. How I can setup my machine and write first Java program... and run first Java program: Create program in Note pad: Step 1: Open
Three Dimensional Array program
the multidimensional array we are going to make a matrix. Now in this program use... Three Dimensional Array program       This is a very simple Java program. In this program we
create dynamic array in javascript
create dynamic array in javascript  How to create dynamic array in javascript
declare a variable that will store an array of 5 objects
declare a variable that will store an array of 5 objects  Q7. Give a declaration for a variable that will 'store' an array of 5 Card objects..., kindly could you help me to be a master of Java I would be appreciate it. thank
Create a java program using Java with LinkedLists
Create a java program using Java with LinkedLists  Assignment is -- Question For this part of the assignment, you will develop a Java application... that reverses the list in place (that is, does not create a new copy of the list) Step 2
how to create array in python
how to create array in python  Hi, how to create array in python? I want to create an array in Python and add some values to it. Thanks   Hi, You can create a new array with the code myArray = [] and after
how to create array in r
how to create array in r  Hi, In R Programming how array is created? how to create array in r? Explain me the process of array creation using.... You can create an array with the help of array keyword. Following is an example
Program to implement array of Objects.
Program to implement array of Objects.  Create a class it has.... Initialize an array of objects. Pass a name from the command line & search for the name in the array of objects , if it is existing print the information
Static variable in java
Static variable in java. Static is a keyword in java used to create static.... Static variable are created when the program starts and destroys when the program stop. Visibility of class/static variable is same but mostly
Create an array of 5 doubles...
Create an array of 5 doubles...  Part one In a Java program, create an array of 5 doubles. Have the user input values into these array items inside... three Write a simple program that will have an integer division inside a try
create associative array from array javascript
create associative array from array javascript  How to create associative array from an array in JavaScript? Please suggest. Thanks
one dimensional array program
one dimensional array program  Design and implement a java program that will read a file containing numbers and compute the following statistics: the rannge( low, high), the average and the median(middle number). Notes
how to make a program on array
how to make a program on array  When you make a program on array that the element will move downward and upward and when you input twice 0 then thats the time that it will not move. pls. give me a formula...tnx
Two Dimensional Array Program
Two Dimensional Array Program Using Nested for loop       This is a simple Java array  program . In this session we will teach how to use of a two dimensional array
How to create dynamic array in C?
How to create dynamic array in C?  How to create dynamic array in c programming language?   Dynamic Array in C Tutorial
Converting jsp variable to java variable
Converting jsp variable to java variable  Hi how to convert java script variable to java variable on same jsp page
Use of Array in Java
Use of Array in Java      ... that you can write a program on array by yourself. An array works a container... way to create a array is by using new operator. e.g.. : a = new int[5
Reverse integer array program
Reverse integer array program  Been tasked with the following question: Write a method that accepts an integer array and returns a new array with all the elements in reverse order. For example, if the input array is [2, 4, 6, 8

Ads