Results 1 to 8 of 8
  1. #1
    zaydz is offline Member
    Join Date
    Jun 2010
    Posts
    11
    Rep Power
    0

    Default function illegal start of expression

    this

    how to solve this. as i know the code for making a function is already right. :confused:

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    If you're serious about needing help, you're best posting your code here with any error messages. Please click on my link to see how to use code tags though.

    Edit: and also, you should know that you can't nest methods inside of each other. Post your code and I can give you the details about what this implies.

    Much luck.

  3. #3
    zaydz is offline Member
    Join Date
    Jun 2010
    Posts
    11
    Rep Power
    0

    Default

    Java Code:
    import javax.swing.*;
    class SD 
    {
    	public static void main(String[] args) 
    	{
    		int K,G;
    		String x= "ada";
    		int siswa[][]= new int [5][1];
    
    		for (int i=5;i>0 ;i-- )
    		{
    			for (int j=1;i>0 ;j-- )
    			{
    				siswa[i][j]=0;
    			}
    		}
    
    		
    		while (x=="ada")
    		{	G=Integer.parseInt(JOptionPane.showInputDialog(null,"masukan gender 0 = Pria & 1 = Wanita"));
                K=Integer.parseInt(JOptionPane.showInputDialog(null,"masukan kelas dari 1-6"));
    
                siswa[K][G]=siswa[K][G]++;
    
                x=JOptionPane.showInputDialog(null,"apakah masih ada input??");
    		}
    		
    					
    		static int totalperkelas (int ke)
    		{
                int jumlah = 0;
                jumlah = siswa[0][ke] + siswa[1][ke];
                return(jumlah);
    		}}
    the error message is
    SD.java:29: illegal start of expression
    static int totalperkelas (int ke)
    ^
    SD.java:29: ';' expected
    static int totalperkelas (int ke)
    ^
    SD.java:29: ';' expected
    static int totalperkelas (int ke)
    ^
    3 errors

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Thanks. Again, your problem is that you're nesting a method within a method (we don't say "function" in Java). Specifically, the totalperkelas method is nested within the main method. The solution is to pull the totalperkelas method outside of main.

  5. #5
    zaydz is offline Member
    Join Date
    Jun 2010
    Posts
    11
    Rep Power
    0

    Default

    eureka.!
    thankies for your help. Fubarable :)

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by zaydz View Post
    eureka.!
    thankies for your help. Fubarable :)
    You're quite welcome. Oh, and thanks for using code tags, and a big welcome to the Java-forums.org!

  7. #7
    zaydz is offline Member
    Join Date
    Jun 2010
    Posts
    11
    Rep Power
    0

    Default

    errr.. fubarable 1 more k? :P

    Java Code:
    int siswa[][]= new int [5][1];
    for (int i=5;i>0 ;i-- )
    		{
    			for (int j=1;i>0 ;j-- )
    			{
    				siswa[i][j]=0;
    			}
    		}
    why it say out of bound.? as i know the looping code is alright
    thanks before

    SOLVED
    Last edited by zaydz; 06-09-2010 at 04:22 AM.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Illegal Start of expression
    By Macca07 in forum New To Java
    Replies: 3
    Last Post: 11-23-2009, 08:43 AM
  2. Illegal start of expression
    By Basit56 in forum New To Java
    Replies: 2
    Last Post: 08-18-2009, 09:12 AM
  3. Illegal Start of an Expression
    By ddatta8 in forum New To Java
    Replies: 3
    Last Post: 12-20-2008, 08:40 PM
  4. illegal start of expression
    By razmyasdfg in forum CLDC and MIDP
    Replies: 2
    Last Post: 07-27-2008, 10:44 PM
  5. Illegal start of expression
    By gabriel in forum New To Java
    Replies: 2
    Last Post: 08-01-2007, 05:09 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
  •