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



Home Answers Viewqa Java-Beginners Create an array of 5 doubles...
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


PS
Create an array of 5 doubles...
1 Answer(s)      2 years and 4 months ago
Posted in : Java Beginners


Part one In a Java program, create an array of 5 doubles. Have the user input values into these array items inside a loop using JOptionPane. Using the loop, calculate the sum and average of the 5 numbers and output this using JOptionPane.

Part two Same as above, only have a second loop (enhanced for loop) do the summing to calculate the average.

Part three Write a simple program that will have an integer division inside a try block followed by a catch block with an appropriate argument type. Inside the catch block, output a message saying that division by zero is not allowed. Run this code with and without the denominator being zero. When the denominator is not zero, output a message displaying the calculated ratio.


Advertisement
View Answers

May 22, 2012 at 7:33 AM


import javax.swing.JOptionPane;

public class FiveDoubles 
{
    /**
     * @param args
     */
    public static void main(String[] args) 
    {
            String input;
            double data[] = new double[5];  
            double sum = 0, average;
            for ( int i = 0; i < data.length; i++ )
            {
                input = JOptionPane.showInputDialog("INPUT A NUMBER");
                data[i] = Double.parseDouble(input);
            }
                for ( int j = 0; j < data.length; j++)
                    sum += data[j];
                average = sum/data.length;
                String output = "Value/n";
                for (int k = 0; k < data.length; k++)
                    output += data[k] + "\n";
                JTextArea outputArea = new JTextArea();
                outputArea.setText(output);
                JOptionPane.showmessageDialog(null, outputArea, "SumAverage",
                        JOptionPane.INFORMATION_MESSAGE);
                System.exit(0);
        }
    }


Related Tutorials/Questions & Answers:
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 a loop using JOptionPane. Using the loop, calculate the sum and average of the 5
Create Array ??
Create Array ??   Question in e-clips program: Part 1. Array Implementation -Create a class called ‚??PhoneEntry‚?? which can be used to store the name and number of ONE client. -Create a class called ‚??MyArrayList‚?? which
Advertisements
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... you   Declare Array of 5 objects in the following way: int list[]=new
create dynamic array in javascript
create dynamic array in javascript  How to create dynamic array in javascript
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
returning doubles with 2 decimals JAVA
returning doubles with 2 decimals JAVA  Hi all. I'm writing a program where users input the cost of an item (in the constructor), so for example, Item (string name, double cost, int qty) { ... } I have a method public double
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 counter in mySQL 5 database through Java - SQL
Create a counter in mySQL 5 database through Java  Dear Editor... question regarding Java & mySQL 5 database... for 12 times. May i know how to create a counter (some sort like word search
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
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
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
Create array of random size
Create array of random size In this tutorial, you will learn how to create a randomly sized integer array. For this, we have declared an array and using... have create a text field to enter any index of array and another textfield
how to create a zip by using byte array
how to create a zip by using byte array  hi, How to convert byte array to zip by using java program.can u plz provide it...... Thanks, krishna
How to create binary search tree using an array?
How to create binary search tree using an array?  hello people, pls guide me on the topic above. i have an string array, i want to make a binary search tree based on data inside this array. the array contains names of people
How to create a long array with the help of long buffer.
How to create a long array with the help of long buffer.  In this tutorial, we will see how to create a long array with the help of long buffer...; long[] array() The array() method returns long array based
Create a int array with the help of int buffer.
Create a int array with the help of int buffer.  In this tutorial, we will see how to create a int array with the help of int buffer. IntBuffer API...[] array() The array() method returns int array based on int buffer
Create a int buffer by wrapping an int array into a buffer.
Create a int buffer by wrapping an int array into a buffer.  In this tutorial, we will see how to create a int buffer by wrapping an int array...; The wrap(....) method wrap an existing int array and create int buffer
Create a long buffer by wrapping an long array.
Create a long buffer by wrapping an long array.  In this tutorial, we will see how to create a long buffer by wrapping an long array into a buffer...; The wrap(....) method wrap an existing long array and create long buffer
Create a short array with the help of short buffer.
Create a short array with the help of short buffer.  In this tutorial, we will see how to create a short array with the help of short buffer...; short[] array() The array() method returns short array based
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
Array
Array  can we create an array of size 1 lakh in java programming
Array
(System.in); int array[]=new int[5]; System.out.println("Enter Array Elements...Array  What if i will not declare the limit index of an array, how will I declare an array and store values with it using loop?   Hi Friend
Array
Array  How do i insert elements into an array up to a limit from command prompt using SOP statement.like Enter range:3 Enter elements: 1 5 3  ...("Enter Range: "); int size=input.nextInt(); int array[]=new int[size
array
array  create an array in which no element is duplicate. if duplicate then tell to user duplicate. duplicacy is tell to user during when he enter the element
array
array  create an array in which no element is duplicate. if duplicate then tell to user duplicate. duplicacy is tell to user during when he enter the element
in_array
in_array  in_array in php
is _array()
is _array()  is_array() in php   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
is _array()
is _array()  is _array()   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
Array's
Array's  I have to finish an "order page". that checks 2 dropdown boxes and a set of radio buttons and put the results into a set of textboxes, 1 line at a time, then calculate a total. I know I need to create an array, but I'm
array
array  Hi i have array like {1,2,3,4,,5,5,6,6} then how can i display 1 time , 5 - 2times, 3- 2times thank kalins naik   Here is an example that store some integers into an array and find the occurrence of each
numbers divisible by 5 and 6
numbers divisible by 5 and 6  Find the first ten numbers which are greater than Long.MAX_VALUE divisible by 5 and 6
Advertisements
 

 

 

DMCA.com