Difference between revisions of "Creating an Array"

From CompSciWiki
Jump to: navigation, search
Line 12: Line 12:
  
 
|Solution=
 
|Solution=
{public class Creating{
+
<pre>
 +
public class Creating{
 
   public static void main(String[] args){
 
   public static void main(String[] args){
 
     int[] intArray = {56, 34, 75, 89, 78, 87, 71, 67, 98, 85};
 
     int[] intArray = {56, 34, 75, 89, 78, 87, 71, 67, 98, 85};
 
     double[] decimalArray = {0.56, 0.34, 0.75, 0.89, 0.78, 0.87, 0.71, 0.67, 0.98, 0.85};
 
     double[] decimalArray = {0.56, 0.34, 0.75, 0.89, 0.78, 0.87, 0.71, 0.67, 0.98, 0.85};
 
   }
 
   }
}}
+
}
 +
</pre>
  
 
}}
 
}}

Revision as of 12:15, 1 April 2010

Back to the Program-A-Day homepage

Problem

There are ten students with ten grades. Instead of storing every single grade in a single variable it is easier to store this information in an array. Given that the grades are 56%, 34%, 75%, 89%, 78%, 87%, 71%, 67%, 98%, 85%, store the grades in an integer array as percents and convert them to decimals and store them in a double array.

 

SideSectionTitle

float
Taken from http://www.flickr.com/photos/daniello/565304023/

An image or By Students section

Solution

public class Creating{
  public static void main(String[] args){
    int[] intArray = {56, 34, 75, 89, 78, 87, 71, 67, 98, 85};
    double[] decimalArray = {0.56, 0.34, 0.75, 0.89, 0.78, 0.87, 0.71, 0.67, 0.98, 0.85};
  }
}

Code

SolutionCode goes here. Please DO NOT put your code in <pre> tags!

Back to the Program-A-Day homepage