Results 1 to 9 of 9
  1. #1
    butterfly92 is offline Member
    Join Date
    May 2012
    Location
    Lebanon
    Posts
    3
    Rep Power
    0

    Default array..new to java

    hello,
    iam a student which has started learning java recently
    the question is by using arrays dread a list os 5 numbers and display their reserve order
    the problem is after comiling it in bluej there was an error,the code which is in red where is the error??
    the are writing to me class expected ,,,so please help how could i fix that
    Java Code:
    import java.util.Scanner;
    public class ArrayReverse {
    
    public static void main(String []args) {
       Scanner input=new scanner(system.in);
       int nbr[]=newInt[5];
       for(int i=0 ; i<nbr.lenght;i++) {
          System.out.print("enter a number");
    [COLOR="#FF0000"]nbr[i]=input.nextInt[];[/COLOR]
       }
       System.out.print("the numbers in reverse order");
       for (int i=nbr.lenght-1;i>=0;i--)
          System.out.print(nbr[i]);
       }
    }
    Last edited by JosAH; 06-13-2012 at 03:33 PM. Reason: Changed [center] ... [/center] tags to [code] ... [/code] tags

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Default Re: array..new to java

    Please edit your code and properly format it and wrap it in code tags. BB Code List - Java Programming Forum

    there was an error,the code which is in red where is the error??
    Please copy and post here the full text of the error message.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default Re: array..new to java

    nextInt is a method, so a call should be nextInt(), not nextInt[].

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    butterfly92 is offline Member
    Join Date
    May 2012
    Location
    Lebanon
    Posts
    3
    Rep Power
    0

    Default Re: array..new to java

    Quote Originally Posted by Norm View Post
    Please edit your code and properly format it and wrap it in code tags. BB Code List - Java Programming Forum


    Please copy and post here the full text of the error message.


    when ifixed the problem by changing the array to nextInt()
    another message appeared:
    Scanner input=new scanner(system.in);<<<<<<here((((error cannot find a symbol)))))

  5. #5
    butterfly92 is offline Member
    Join Date
    May 2012
    Location
    Lebanon
    Posts
    3
    Rep Power
    0

    Default Re: array..new to java

    Quote Originally Posted by JosAH View Post
    nextInt is a method, so a call should be nextInt(), not nextInt[].

    kind regards,

    Jos

    when ifixed the problem by changing the array to nextInt()
    another message appeared:
    Scanner input=new scanner(system.in);<<<<<<here((((error cannot find a symbol)))))

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Default Re: array..new to java

    error cannot find a symbol
    What symbol is not being found?
    Java is case sensitive. Check your spelling.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    chipp's Avatar
    chipp is offline Member
    Join Date
    Jul 2011
    Posts
    62
    Rep Power
    0

    Default Re: array..new to java

    by the way:
    Java Code:
    int nbr[]=newInt[5];
    should be:
    Java Code:
    int nbr[] = new int [5];

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default Re: array..new to java

    Quote Originally Posted by butterfly92 View Post
    Scanner input=new scanner(system.in);<<<<<<here((((error cannot find a symbol)))))
    Java is not Basic, nor is it C#; Java has a very consistent capitalization of identifier names; better get used to it.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    Ksharp is offline Banned
    Join Date
    Jun 2012
    Location
    Beijing,China
    Posts
    34
    Rep Power
    0

    Default Re: array..new to java

    Here is a snippet code. You need check it on your own.

    Java Code:
           Scanner input=new Scanner(System.in);
       int nbr[]=new int[5];
       for(int i=4 ; i>=0;i--) {
          System.out.println("enter a number :");
          nbr[i]=input.nextInt();
       }
       System.out.println("the numbers in reverse order");
       for(int j=0;j<nbr.length;j++)
          System.out.print(nbr[j]+" ");
       }

    Ksharp

Similar Threads

  1. Java 2D Array
    By The Dark Dragon in forum New To Java
    Replies: 3
    Last Post: 11-27-2011, 08:00 AM
  2. Java Array
    By lary in forum New To Java
    Replies: 8
    Last Post: 05-10-2011, 10:44 AM
  3. `java array
    By shane123 in forum New To Java
    Replies: 18
    Last Post: 03-22-2010, 12:42 AM
  4. How to transfer 1D array in JAVA to 3D array in C
    By fishwater00 in forum New To Java
    Replies: 0
    Last Post: 07-31-2009, 06:24 PM
  5. how to convert a Java array to a java stack?
    By pompeez in forum New To Java
    Replies: 2
    Last Post: 08-13-2007, 02:41 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
  •