Results 1 to 5 of 5
  1. #1
    raladin3d is offline Member
    Join Date
    Apr 2011
    Posts
    2
    Rep Power
    0

    Default Array code problem

    Hello.
    Ok so before I begin, I am new to Java and I am trying to work and practice as much as possible.
    anyway, I am trying to make a small program (using arrays) where I plug in the names and marks for people and then the output shows them in table.
    Now I wrote this code, but I am not sure if it is correct, so now I am confused.

    Note: lots of variables are just randomly named, so please excuse that, I was trying to change them to try and make the program work.

    Java Code:
    import java.util.Scanner; 
    import java.io.*;
     
    public class IfStatmenteno {
       
        public static void main(String[] args) {
         System.out.println ("Enter the number of subjects you want to input");
         numberr= in.nextLine();
         int[] marks = new int[numberr]
          
         Scanner in = new Scanner(System.in);
         String subject1;
         System.out.println ("Please Enter your first name");
          subject1 = in.nextLine();
         String subject2;
         System.out.println ("Please Enter your 2nd name");
          subject2 = in.nextLine();
         String subject3;
         System.out.println ("Please Enter your 3rd name");
          subject3 = in.nextLine();
         String subject4;
         System.out.println ("Please Enter your 4th name");
          subject4 = in.nextLine();
         String subject5;
         System.out.println ("Please Enter your 5th name");
          subject5 = in.nextLine();
          
          
         int mark1;
         System.out.println ("Please Enter your first mark");
          mark1 = in.nextLine();
         int mark2;
         System.out.println ("Please Enter your second mark");
          mark2 = in.nextLine();
         int mark3;
         System.out.println ("Please Enter your 3rd mark");
          mark3 = in.nextLine();
         int mark4;
         System.out.println ("Please Enter your 4th mark");
          mark4 = in.nextLine();
         int mark5;
         System.out.println ("Please Enter your 5th mark");
          mark5 = in.nextLine();
        System.out.println ("Part No.\tItem Name");
    System.out.println ("*******\t\t*********");
    int numbers[] = {mark1,mark2,mark3,mark4,mark5};
    String ItemNames[]= {"\t\t"+subject1,"\t\t"+subject2,"\t\t"+subject3,"\t\t"+subject4,"\t\t"+subject5};
    for(int counter=0;counter < numbers.length;counter++){
    System.out.println( numbers[counter] + "\t" +ItemNames[counter]);
    }
    }
    }

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    You're not sure if it's correct? You can check that by comparing your expected output to your produced output. If it produces that output correctly, and has no errors, then I suppose that would be "correct".

    If it's not doing what you expect, please post the expected & produced outputs here (and the full text of any errors you may get) and we can try to help you sort them out.

  3. #3
    raladin3d is offline Member
    Join Date
    Apr 2011
    Posts
    2
    Rep Power
    0

    Default

    Quote Originally Posted by Zack View Post
    You're not sure if it's correct? You can check that by comparing your expected output to your produced output. If it produces that output correctly, and has no errors, then I suppose that would be "correct".

    If it's not doing what you expect, please post the expected & produced outputs here (and the full text of any errors you may get) and we can try to help you sort them out.
    yeah sorry my bad, I meant I always tried running it but I always receive this error.

    Java Code:
    Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    	x cannot be resolved to a variable
    	in cannot be resolved
    	Type mismatch: cannot convert from int[] to int
    	Syntax error, insert "ArrayInitializer" to complete ArrayCreationWithArrayInitializer
    	Syntax error, insert ";" to complete LocalVariableDeclarationStatement
    
    	at IfStatmenteno.main(IfStatmenteno.java:17)

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    The error tells you something that is wrong,
    Java Code:
    Syntax error, insert ";" to complete LocalVariableDeclarationStatement

  5. #5
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    Note that, while the error says it's on line 17, it actually is not. However, you ARE missing a semicolon somewhere in the code. ;)

Similar Threads

  1. Replies: 0
    Last Post: 02-21-2011, 11:50 AM
  2. Array Code difficulties
    By NixasMuraki in forum New To Java
    Replies: 2
    Last Post: 02-08-2011, 12:17 AM
  3. code using array
    By java008 in forum New To Java
    Replies: 11
    Last Post: 12-18-2008, 10:44 AM
  4. please i need the code of comparing these two array lists.
    By raj reddy in forum JavaServer Pages (JSP) and JSTL
    Replies: 5
    Last Post: 04-18-2008, 07:42 AM

Posting Permissions

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