Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners create and use an array variable in a java program

Have Programming Question? Ask it here!
 
 
 


richard phillips
create and use an array variable in a java program
1 Answer(s)      3 years and 6 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


Advertisement
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
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 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
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
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
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‚
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
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
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 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&
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
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
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
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
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
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 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. Create a session variable code in PHP
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
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
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
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
Use char variable as integer
Description: Here in this example you will see how a char variable works like a integer. The char variable works with pre and post increment operators. Code: public class CharInt {   
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
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
Java Transient Variable
Java Transient Variables Before knowing the transient variable you should firs know about the Serialization in java. Serialization means making a object... mark that object as persistent. You can also say that the transient variable
Java Final Variable
Java Final Variable  I have some confusion --Final variable has single copy for each object so can we access final variable through class name,or it is necessary to create object for accessing final variable
how to use button in array
how to use button in array  plz tell me how to code for button in array
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
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
Java example program to get the environment variable
Java example program to get the environment variable       java get environment variable...:\javaexamples>java GetEnvironmentVariable Environment Variable are =>
Instance variable in java
Instance variable in java In this section you will learn about Instance variable in java. In java all variable must be declared before they are used... is one of the data type in java ,identifier is one of the name of the variable
Java Array Usage
Java Array Usage       We have already discussed that to refer an element within an array, we use... in the program that which elements are of interest in an array. To find the elements
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
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
String Array
how to make use of string array. In the java programming tutorial string, which... in this program we are going to use string type array. We have to used array as data... of program: In this program you will be read how to use string of array. First of all
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
program to create nested tables
program to create nested tables  program to create nested tables
Store Variable in Java
Store Variable in Java  How to store Variables in Java?   public class DoubleTest { public static void main(String[] args) { double...(aDouble); // Outputs 7.21 } }   Variable in Java
java program to create xml file with append data in well-formed
java program to create xml file with append data in well-formed   Sorry sir your given xml append data program is not well-formed. I'll make you more clear what I want. If this is my xml file Tom Cruise 45 Now when I append
PHP Array, PHP Array Tutorials and Example code
to explain the PHP Array in detail. You will learn how to create, use and manipulate the array in your PHP program. PHP array is ordered map that is used very frequently in the PHP program. Learn the PHP Array with examples
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
Array in java
in memory at fixed size. We can use multiple type array. It can be used in Java, C++, PHP and any other programming languages. We can use array in program...Array in java In following example we will discuss about Array in Java. Array
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
Get Environment Variable Java
Get Environment Variable Java       In this example we are getting environment variable. To get the environment variable we use getenv() method. Map is an interface
String Array In Java
String Array In Java       In this section, you will learn how to use string array in Java. Here, you will see how to declare a string array and the syntax for using in the program
Advertisements
 

 

 

DMCA.com