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: String[] and Int[]

  1. #1
    Member
    Join Date
    Jan 2011
    Posts
    88
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Question String[] and Int[]

    this is the first time ive ever attempted this.

    heres my code:

    	for (Player p: new Player) {
    	public static int[p.pkr] String[] pvpRank = { 1, "Newbie", 5, "Novice", 10, "Feared", 15, "Mighty", 20, "Respected", 35, "Master", 50, "Legondary"};
    	}

    heres my error

    .\palidino76\rs2\Config.java:15: illegal start of type
            for (Player p: new Player) {
            ^
    .\palidino76\rs2\Config.java:15: ')' expected
            for (Player p: new Player) {
                         ^
    .\palidino76\rs2\Config.java:15: illegal start of type
            for (Player p: new Player) {
                           ^
    .\palidino76\rs2\Config.java:15: ';' expected
            for (Player p: new Player) {
                                     ^
    .\palidino76\rs2\Config.java:16: illegal start of expression
            public static int[p.pkr] String[] pvpRank = { 1, "Newbie", 5, "Novice",
    10, "Feared", 15, "Mighty", 20, "Respected", 35, "Master", 50, "Legondary"};
            ^
    .\palidino76\rs2\Config.java:16: illegal start of expression
            public static int[p.pkr] String[] pvpRank = { 1, "Newbie", 5, "Novice",
    10, "Feared", 15, "Mighty", 20, "Respected", 35, "Master", 50, "Legondary"};
                   ^
    .\palidino76\rs2\Config.java:16: ';' expected
            public static int[p.pkr] String[] pvpRank = { 1, "Newbie", 5, "Novice",
    10, "Feared", 15, "Mighty", 20, "Respected", 35, "Master", 50, "Legondary"};
                         ^
    .\palidino76\rs2\Config.java:16: illegal start of expression
            public static int[p.pkr] String[] pvpRank = { 1, "Newbie", 5, "Novice",
    10, "Feared", 15, "Mighty", 20, "Respected", 35, "Master", 50, "Legondary"};
                             ^
    .\palidino76\rs2\Config.java:16: ';' expected
            public static int[p.pkr] String[] pvpRank = { 1, "Newbie", 5, "Novice",
    10, "Feared", 15, "Mighty", 20, "Respected", 35, "Master", 50, "Legondary"};
                               ^
    .\palidino76\rs2\Config.java:16: not a statement
            public static int[p.pkr] String[] pvpRank = { 1, "Newbie", 5, "Novice",
    10, "Feared", 15, "Mighty", 20, "Respected", 35, "Master", 50, "Legondary"};
                                ^
    .\palidino76\rs2\Config.java:16: ';' expected
            public static int[p.pkr] String[] pvpRank = { 1, "Newbie", 5, "Novice",
    10, "Feared", 15, "Mighty", 20, "Respected", 35, "Master", 50, "Legondary"};
                                   ^
    11 errors
    Press any key to continue . . .

    idk if what im trying to do is self explanatory or not but here it is in a nut shell

    im trying to make an outprint like "You are a "+pvpRank+" pker" what the rank is (newbie, novice, ect.) is defined by what ever "pkr" equals. So if pkr = 1 then the outprint would be "You are a Newbie pker".

    I know i could use if statements but those can take up a lot of space and look sloppy


  2. #2
    Member
    Join Date
    Jun 2011
    Location
    Rhode Island
    Posts
    69
    My Mood
    Bored
    Thanks
    11
    Thanked 7 Times in 6 Posts

    Default Re: String[] and Int[]

    check this tutorial out and you may see what your doing wrong.

    for each loops

  3. #3
    Member
    Join Date
    Jan 2011
    Posts
    88
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: String[] and Int[]

    got it 3 errors left.

    .\palidino76\rs2\Config.java:15: ']' expected
            public static int[Engine.Player.pkr] String[] pvpRank = { 1, "Newbie", 5
    , "Novice", 10, "Feared", 15, "Mighty", 20, "Respected", 35, "Master", 50, "Lego
    ndary"};
                              ^
    .\palidino76\rs2\Config.java:15: ';' expected
            public static int[Engine.Player.pkr] String[] pvpRank = { 1, "Newbie", 5
    , "Novice", 10, "Feared", 15, "Mighty", 20, "Respected", 35, "Master", 50, "Lego
    ndary"};
                                    ^
    .\palidino76\rs2\Config.java:15: <identifier> expected
            public static int[Engine.Player.pkr] String[] pvpRank = { 1, "Newbie", 5
    , "Novice", 10, "Feared", 15, "Mighty", 20, "Respected", 35, "Master", 50, "Lego
    ndary"};
                                               ^
    3 errors
    Press any key to continue . . .

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: String[] and Int[]

    public static int[p.pkr] String[]
    what are you trying to make up here?
    You are stuck with what the java language allows. Arrays can only contain elements of one type.

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: String[] and Int[]

    I'm assuming this code is inside of some method? remove the "public static" keywords. They're only used in class/object member declarations.

    Also, you're trying to cram both int data and String data into one array. While it's technically possible, it's recommended against to do it that way. Try creating an object which contains an integer field and a String field, then create an array of that object.

  6. #6
    Member
    Join Date
    Jan 2011
    Posts
    88
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: String[] and Int[]

    ok that makes since. and no its not in any method at all

Similar Threads

  1. private Map<String, ArrayList> xlist = new HashMap<String, ArrayList>();
    By Scotty in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 21st, 2011, 08:37 AM
  2. Replies: 18
    Last Post: March 2nd, 2011, 10:52 AM
  3. [SOLVED] String Matcher finding only char not a whole string
    By Kakashi in forum What's Wrong With My Code?
    Replies: 11
    Last Post: February 18th, 2011, 09:58 AM
  4. Replies: 2
    Last Post: December 22nd, 2010, 09:21 AM
  5. Replies: 2
    Last Post: November 3rd, 2009, 06:28 AM