create and use an array variable in a java program

Ads

 
 

Share on Google+Share on Google+

richard phillips
create and use an array variable in a java program
1 Answer(s)      6 years and 7 months ago
Posted in : Java Beginners

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

Ads
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
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
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
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
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
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‚
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 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
java 2 d array program
java 2 d array program  write a program 2-d matrix addition through user's input?  Hi Friend, Try the following code: import java.util.*; class MatrixAddition{ public static void main(String[] args
What is use of a abstract variable?
What is use of a abstract variable?   Hi, What is use of a abstract variable? thanks
What is use of a abstract variable?
What is use of a abstract variable?   Hi, What is use of a abstract variable? thanks
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
How I get a variable from java script to use it in the scriptlet of jsp.
How I get a variable from java script to use it in the scriptlet of jsp.  Hi i want to get the tinyUrl value in the scriptlet of jsp. // Bit.ly API var url="http://cplive.com/dealDetail.do?method=displayDealDetail&
Use of array() method of FloatBuffer class in java.
Use of array() method of FloatBuffer class in java.  In this tutorial, we will see how to create a float array of float buffer. FloatBuffer API...[] array() The array() method returns float array based on float
Array list java program - Java Interview Questions
Array list java program  Create an employee class with an employee... an employee id is given, display his name & address? Please provide the DETAIL java code for this query i.e.,how we can create a class for employee with id's,name
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
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
How to Create a ByteBuffer using Byte Array in java.
How to create a ByteBuffer using Byte Array in java.      ..., we will discuss how to creates a buffer using byte array. The ByteBuffer ... Description static ByteBuffer wrap(byte array
What is instance variable in Java?
What is instance variable in Java?  Hi, What is instance variable in Java? What is the use of instance variable? Thanks   Hi, In Java... as a member variable. If you create 10 instance of the class then each instance
program of array
program of array  write a program that initializes an array with ten random integers and then prints four lines of output,containing:every element at an even index,every even element,all elements in reverse order,and only
create dynamic array in javascript
create dynamic array in javascript  How to create dynamic array in javascript
What is Array in Java?
What is Array in Java?  Hi, What is Array in Java? How to create an array in Java and use it? Thanks   Hi, Array is very important in Java as it is used heavily in programming. Array is Java is a container object
Java variable
Java variable   To what value is a variable of the String type automatically initialized
program in array
program in array  print("code sample");write a program that initializes an array with ten random integers and then prints four lines of output...[]=new int[10]; System.out.println("Array of Random Numbers
PHP Array
how to use PHP Array in your PHP program. The PHP Array is very useful... use following code: <? echo $fruit_array[2] ?> Following code shows how to create simple array: // Create a simple array. $my_array = array(1, 2, 3, 4

Ads

 
Advertisement null

Ads