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

 
 


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

View Answers

March 8, 2011 at 2:39 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]);
            }
        }
    }
}

March 8, 2011 at 2:39 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]);
            }
        }
    }
}

March 8, 2011 at 2:39 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]);
            }
        }
    }
}

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 Pages:
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
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
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
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â
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
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
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
Example of a instance variable
, not the updated one . In this program we are showing that how a instance variable.... First create a class named NonStaticVariable. Declare one global variable... of the instance variable in both the object is same.  Code of this program
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 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
Local Variable ,Package & import
define your Java program, and you name the packages you want to use from other...Local Variable ,Package & import A local variable has a local scope.Such a variable is accessible only from the function or block in which
Variable Names
Java Notes Variable Names... to the casual observer the intent of its use. One-character variable names should be avoided... Special case: Domain names. It's important to use variable names which
Java Array Initialization
of the Array, we use field length, as shown. Output for the given program... Java Array Initialization       After declaring an array variable, memory is allocated
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
Local Variable and Instant Variable
they compile fine. But in the case of local variable in Java, local variable in Java do...Local Variable and Instant Variable  difference between Local Variable and Instant Variable   Difference between local variable
Example of a class variable (static variable)
can call class variable directly inside the main method. To see the use of a static variable first of all create a class StaticVariable. Define one static... Example of a class variable (static 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
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
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
PHP Global Variable
PHP  Global Variable To access global variable in PHP we need to use... to access the globally declared variable. There is no limit to use global keyword within a program. $GLOBALS is an associative array containing references
JavaScript Array
. The Program create a HTML page specifying a button name 'Display Array Values... array union in Java Script. The code contain a script that include a variable arr1... use the Array Object which has the facility to store multiple values
String Array - Java Beginners
of (10d10,10d20); How am I suppose to make use of 10,10,10 and 20, in my program... for me to manipulate a String Array. For Example, I had a String Array ("3d4","1d6"), and I need the values 3,4,1 and 6 in my program. I wish could tell me
Array
Array  can we create an array of size 1 lakh in java programming
Extracting variable from jsp
Extracting variable from jsp  how to Write a java program which..., these field values will get inserted into the excel file. 1)Create form.jsp <html>...)Create excelFile.jsp <%@page import="java.io.*"%> <%@page import
PHP Variable Global
variable is to use predefined $GLOBALS array within the PHP. $GLOBALS array is an associative array that containing a reference to every individual variable... can use global variable in different-different ways, For example : PHP Global
Creating a Local Variable in JSP
on the browse we will use the out implicit object.  The code of the program...Creating a Local Variable in JSP          In jsp when we have to create a method
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
PHP Variable Scope
either use global keyword or $GLOBALS array keyword. Another way of scoping ...PHP Variable Scope: In every language every variable has a scope, may be within a block or within the whole program etc.  Generally the scope
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
Static Variable
Static Variable  What is the basic use of introducing static variable type in java?Please explain clearly....   The Static means that a certain object/variable is resident in memory and accessed each time an instance
The Array Palindrome Number in Java
The Array Palindrome Number in Java       This is a Java simple palindrome number program... program. The array palindrome number arrange the array number. This session
JSP Array
. The below example gives you a demo on use of Array in JSP. Understand with Example... create a page directive, that describe the language used is Java. The JSP code... elements. When you want to iterate through this array, you have to use for loop
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
ARRAY
ARRAY  CAN SOMEONE HELP ANSWER THIS QUESTION PLEASE Write a program... election and the votes received by each candidate. The program should then output... of the total votes received by the candidate. Your program should also output
ARRAY
ARRAY  CAN SOMEONE HELP ANSWER THIS QUESTION PLEASE Write a program... election and the votes received by each candidate. The program should then output... of the total votes received by the candidate. Your program should also output
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
array
array  write a program in java which input n ,a natural number less than 12 and prints the natural number from 1 to n to the power 2 in the form of a spiral.the spiral should move in on anti clockwise direction starting from
java program
java program  write a java program to create an array of size 10 by taking input from bufferreader and find out the average of array elements from that array
java program
java program  write a java program to create an array of size 10 by taking input from bufferreader and find out the average of array elements from that array
java program
java program  write a java program to create an array of size 10 by taking input from bufferreader and find out the average of array elements from that array
C array of pointers
C array of pointers       In this section, you will learn how to create array of pointers... the objects of array pointer. The address of the variablearray[0
Two dimensional array in java
Two dimensional array in java. In this section you will learn about two-dimensional array in java with an example. As we know that array is a collection... dimensional array is defined as an "array of array". In java the element
Using Unicode Variable Names - Java Tutorials
Using Unicode Variable Names 2001-11-23 The Java Specialists' Newsletter [Issue 036] - Using Unicode Variable Names Author: Dr. Heinz M. Kabutz.... Welcome to the 36th edition of "The Java(tm) Specialists' Newsletter
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
Creating a Local Variable in JSP
Creating a Local Variable in JSP      In jsp when we have to create a method or variable we usually declare... the scriptlet directive itself. To print the variable on the browse we will use
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
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.