Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Can anyone help with this question

  1. #1
    Junior Member
    Join Date
    Nov 2018
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can anyone help with this question

    The following exercises are based on those from the lecture notes. Please refer to the lecture notes for any
    information required and then carry out the following exercises plus any additional tasks as described. You will need
    to create Java classes based on those in the lecture notes, or create your own, as appropriate.
    1. Create a file arrayslist, and place the Java code that solves each of the following problems within it.
    (a) Write a Java program that declares and initialises three arrays A, B and C all of length five. A and B are of
    type int and C is of type String.
    (b) Create an int array called D of length five.
    (c) Populate the array of Strings C (question 1) with words of your choice, use a for loop to print out every
    element of the array C.
    (d) Modify your for loop code so that it loops through every element in the array C and at the end tells you
    which of the words in C has the longest length.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Can anyone help with this question

    What have you tried?
    Do you have any specific java programming questions?

    Be sure to wrap all posted code in code tags.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2018
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can anyone help with this question

    I have done this bit
    //one way (notice the int and intArray2[])
    int intArray[] = new int[3];
    intArray[2] = 1;

    //another way (notice the difference with int[] and intArray2)
    int[] intArray2 = new int[3];
    intArray2[2] = 1;

    //array of strings
    String[] strArray = new String[5];
    strArray[2] = "hello";

    //prints hello
    System.out.println(strArray[2]);

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Can anyone help with this question

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    Do you have any questions?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Nov 2018
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can anyone help with this question

    //one way (notice the int and intArray2[])
    int intArray[] = new int[3];
    intArray[2] = 1;

    //another way (notice the difference with int[] and intArray2)
    int[] intArray2 = new int[3];
    intArray2[2] = 1;

    //array of strings
    String[] strArray = new String[5];
    strArray[2] = "hello";

    //prints hello
    System.out.println(strArray[2]);


    i have done the 1st part

    just asking for completion of it

    no more question

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Can anyone help with this question

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    no more question
    What is the purpose of your posts if you do not have any questions?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 1
    Last Post: November 4th, 2013, 05:38 AM