Results 1 to 5 of 5

Thread: Super Confused

  1. #1
    RyanJ is offline Member
    Join Date
    Oct 2016
    Posts
    2
    Rep Power
    0

    Post Super Confused

    Hi all,

    I'm super new to JAVA and confused on some homework I have. I have to create an array of names of type String with data ''Carlo'', ''Elisa'', ''Magda'', with a loop to print them, I'm given to modify this code but I'm not sure how I insert the names there.



    public class HelloWorld { public static void main(String[] args ) { int [] a = {10, 20, 30} ; // an array of int for ( int x : a ) { // do something for each “ x ” in “ a ” System. out .println( x );

    Cheers,

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,006
    Rep Power
    34

    Default Re: Super Confused

    Please wrap your code in code tags.
    Also to make the code more readable: only put one statement on each line. There should not be any code following a {


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

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

    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Super Confused

    And show the code causing the error message and also show the error message.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    dmp5658 is offline Member
    Join Date
    Sep 2016
    Posts
    33
    Rep Power
    0

    Default Re: Super Confused

    The code you have to modify is an int array, you need to make that a String array which can hold the names like this
    Java Code:
    String[] nameArray= new String[]{"name1","name2","name3"};  //nameArray is the name of the array and you can input your names in name1, name2 and name3.
    Now you need a for loop to print out the names.

    Java Code:
    for (String i : nameArray)    //This loops through every String you inputted into nameArray
    {
                System.out.println(i); //This prints out every String in the loop
    }
    your output should be
    Java Code:
    name1
    name2
    name3

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Super Confused

    Please do not spoon feed solutions. Otherwise, how will the OP learn. He
    has not yet provided the error message and code that he tried.

    Regards,
    Jim
    Last edited by jim829; 10-01-2016 at 07:18 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. I'm super confused on my homework.
    By Frenchi33 in forum New To Java
    Replies: 1
    Last Post: 09-22-2016, 12:13 PM
  2. I am a super noob with a super noob question.
    By LittleZoppo in forum Java Applets
    Replies: 3
    Last Post: 04-27-2012, 03:50 AM
  3. calling variable using super super..
    By Stephen Douglas in forum New To Java
    Replies: 7
    Last Post: 08-16-2010, 06:12 AM
  4. this() and super() ?
    By bob in forum New To Java
    Replies: 4
    Last Post: 08-13-2009, 04:56 PM
  5. this() vs super()
    By Hevonen in forum New To Java
    Replies: 9
    Last Post: 12-04-2008, 01:43 PM

Posting Permissions

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