Results 1 to 8 of 8
- 06-09-2010, 03:42 AM #1
Member
- Join Date
- Jun 2010
- Posts
- 11
- Rep Power
- 0
function illegal start of expression
this
how to solve this. as i know the code for making a function is already right. :confused:
-
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.
- 06-09-2010, 03:52 AM #3
Member
- Join Date
- Jun 2010
- Posts
- 11
- Rep Power
- 0
the error message isJava 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); }}
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
-
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.
- 06-09-2010, 03:55 AM #5
Member
- Join Date
- Jun 2010
- Posts
- 11
- Rep Power
- 0
eureka.!
thankies for your help. Fubarable :)
-
- 06-09-2010, 04:09 AM #7
Member
- Join Date
- Jun 2010
- Posts
- 11
- Rep Power
- 0
errr.. fubarable 1 more k? :P
why it say out of bound.? as i know the looping code is alrightJava 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; } }
thanks before
SOLVEDLast edited by zaydz; 06-09-2010 at 04:22 AM.
-
Arrays go from 0 to length - 1. So for int[] foo = new int[5], we have
foo[0]
foo[1]
foo[2]
foo[3]
and
foo[4]
Similar Threads
-
Illegal Start of expression
By Macca07 in forum New To JavaReplies: 3Last Post: 11-23-2009, 08:43 AM -
Illegal start of expression
By Basit56 in forum New To JavaReplies: 2Last Post: 08-18-2009, 09:12 AM -
Illegal Start of an Expression
By ddatta8 in forum New To JavaReplies: 3Last Post: 12-20-2008, 08:40 PM -
illegal start of expression
By razmyasdfg in forum CLDC and MIDPReplies: 2Last Post: 07-27-2008, 10:44 PM -
Illegal start of expression
By gabriel in forum New To JavaReplies: 2Last Post: 08-01-2007, 05:09 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks