Create an array of 5 doubles...

Ads

 
 

Share on Google+Share on Google+

PS
Create an array of 5 doubles...
1 Answer(s)      5 years 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.

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

Ads









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
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
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
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
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, You can initialize the int array in following way: int num[] = new int[10
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
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
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
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
Hibernate 5 Annotation Example
Learn to create Hibernate 5 Annotation Example This video instruction... you to create a simple Hibernate 5 application. You can take it further... of Hibernate 5 and MySQL JDBC Driver and use in the project. Create Model class
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
Tutorials   
Java Spring Hibernate Struts Training How do beginners learn about Java? ClassNotFoundException HttpRequestInterceptor java.lang.noclassdeffounderror: org/apache/http/httprequest noclassdeffounderror: org/apache/http/client/methods/httpurirequest java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017 Java brief history

Ads

 
Advertisement null

Ads