#1
| |||
| |||
JAVA array how do i declare an array that accepts 5 doubles in which the user places the values into the array via input box. |
#2
| |||
| |||
Re: JAVA array public class TestScoresDemo { public static void main(String[] args) { // An array with test scores. // Notice that element 3 contains an invalid score. double[] badScores = {97.5, 66.7, 88.0, 101.0, 99.0 }; // Another array with test scores. // All of these scores are good. double[] goodScores = {97.5, 66.7, 88.0, 100.0, 99.0 }; // Create a TestScores object initialized with badScores. try { TestScores tBad = new TestScores(badScores); // The following statement should not execute. System.out.println("The average of the bad scores is " + tBad.getAverage()); } catch (IllegalArgumentException e) { System.out.println("Invalid score found.\n" + e.getMessage()); } // Create a TestScores object initialized with goodScores. try { TestScores tGood = new TestScores(goodScores); System.out.println("The average of the good scores is " + tGood.getAverage()); } catch (IllegalArgumentException e) { System.out.println("Invalid score found.\n" + e.getMessage()); } } } |
#3
| |||
| |||
Re: JAVA array Declare an array variable by specifying the type of data to be stored, followed by square brackets [] Code: dataType[] variableName;
To declare a variable for an array of integers: Code: int[] nums;
To declare a variable for an array of String objects: Code: String[] names;
You may also put the brackets after the variable name (as in C/C++), but that is less clearly related to how Java actually works Code: int nums[]; // not recommended, but legal |
![]() |
|
Tags: java |
Thread Tools | Search this Thread |
|
![]() | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Array of objects in java | Ash maker | Software Development | 5 | 27-02-2010 02:05 AM |
How to convert array to collection in java? | Steadfast | Software Development | 4 | 06-02-2010 04:22 PM |
Help with two dimensional array java | GlassFish | Software Development | 3 | 30-11-2009 01:57 PM |
Array problems in java | NetworkeR | Software Development | 2 | 06-11-2009 02:36 PM |
How to create Generic Array in JAVA | Swetlano | Software Development | 3 | 06-02-2009 07:13 PM |