Results 1 to 2 of 2

Thread: How do i

  1. #1
    jpnym15 is offline Member
    Join Date
    Nov 2007
    Posts
    19
    Rep Power
    0

    Default 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)

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •