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]);
            }
        }
    }
}









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
JSP Create Variable          JSP Create Variable is used to create a variable in jsp. The scriptlets include a java code to be written as <%! %>
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
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‚
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
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
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
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
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...(); int arr[]=new int[10]; System.out.println("Array of Random
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
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
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
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)†
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
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 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
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 session variable.
Create session variable In this example, you will learn how to create session variable in HTML form. You can use your email id to find the session value... an Email field and fix submit buttton.ADS_TO_REPLACE_1 Create a session variable
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
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
Java variable
Java variable   To what value is a variable of the String type automatically initialized
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
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
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
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
Two Dimensional array program
to elements of the array such that the last element become the first one and the first become the last.let the program output elements of the first array...Two Dimensional array program  consider 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
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
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
Two Dimensional Array Program
;    This is very simple program of Java. In this lesson we will learn how to display arrange form of two dimensional array program... a integer for array declaration Two dimensional array program. We are going
create python array of size n
create python array of size n  Hi, I want code to create python array of size n? For example if n=10 then it should create an empty array...   Hi, If you want to fill the array with None then you can use
program to implement array of objects
program to implement array of objects  import java.io.*; import java.util.*; public class dataa { DataInputStream in=new DataInputStream(System.in); int i; int a[i]=int acid[5]; String name1[i]=new String[5
create a string from an array using JavaScript
create a string from an array using JavaScript  How to use "join()" to create a string from an array using JavaScript
program to create nested tables
program to create nested tables  program to create nested tables
Create a Program that Calculates Input
Create a Program that Calculates Input   Create a program that takes user input and does a calculation with it, then prints the results back.... For top points, provide options and make the program pretty. (ASCII art &
program to create node.
program to create node.  Hi i'm new to flex and trying to create a node and it should also have an option of right click wit any properties. how do i do this. Also i need to create a gui having drag and dop options. Please help
PHP Array
how to use PHP Array in your PHP program. The PHP Array is very useful... 3  you can use following code: <? echo $fruit_array[2] ?> Following code shows how to create simple array:ADS_TO_REPLACE_2 // Create a simple
create a jsp program
create a jsp program  please help , create web Application using jsp and jdbc which tacking your name,id and DOB .On clicking to submit Button it stores the information into the database and Displays alll the records
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

Ads