Results 1 to 2 of 2
Thread: How do i
- 11-18-2007, 08:09 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 19
- Rep Power
- 0
How do i
1.) Create a String array called Lester that has 76 Strings
2.) Create a double array called sue that holds 30 numbers, which are all 3.2
3.) Create an int array called jimmy that holds 12 ints and set them through the numbers 1 through 12, then sum them.
(sorry for all the questions, but i'm really new to this and these are practice exam questions)
- 11-18-2007, 08:48 PM #2
Java Code:public class ArrayPractice { public static void main(String[] args) { // Create a String array called Lester that has 76 Strings String[] Lester = new String[76]; // All elements of this array are null. System.out.println("Lester[0] = " + Lester[0]); // Initialize the firs element. Lester[0] = "hello world"; System.out.println("Lester[0] = " + Lester[0]); // Create a double array called sue that holds 30 numbers, // which are all 3.2 double[] sue = new double[30]; // All elements are initialized to default zero value. System.out.println("sue[0] = " + sue[0]); // Initialize to requested initial value. for(int j = 0; j < sue.length; j++) sue[j] = 3.2; System.out.println("sue[12] = " + sue[12]); // Create an int array called jimmy that holds 12 ints // and set them through the numbers 1 through 12, then sum them. int[] jimmy = new int[12]; for(int j = 0; j < jimmy.length; j++) jimmy[j] = j+1; int total = 0; for(int j = 0; j < jimmy.length; j++) total += jimmy[j]; System.out.println("total = " + total); } }


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks