Results 1 to 3 of 3
Thread: Array Code difficulties
- 02-08-2011, 12:11 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 11
- Rep Power
- 0
Array Code difficulties
I'm creating a mini program that makes a roster. I haven't finished it yet, but I'm writing it in BlueJ and it keeps yelling at me and saying that a class is expected for the line that I will mark in the below code. Also I want to make it so the user can enter in how many elements the array will have, but I don't know how to do that either...it's really kind of sad. The code that's marked out and commented at the top was my sad attempt even though I knew it wouldn't work I was kind of hoping...anyway here it is:
import javax.swing.*;
public class Roster{
/*System.out.println("Please type in the number of students in your class.");
Scanner students=new Scanner(System.in);
int intstudents=students.nextLine()-1;*/
String[]names=newString[100/*intstudents*/]; /* Ijust figured that 101 students would be enough this way the teacher will have enough elements for the number of students*/
int[]age=new int[100/*intstudents*/]; //these are parallel arrays
public static void main(String[]args){
new Roster().theWholeClass();
}
public void the WholeClass(){
for(int i=0; i<names.length;i++){
names[i]=JOptionPane.showInputDialog("Type in student's name");
age[i]=int.parseInt(JOptionPane.showInputDialog("Type in student's age");
}
printData();
}
- 02-08-2011, 12:15 AM #2
int is a primitive data type and not a class nor a valid variable name.
- 02-08-2011, 12:17 AM #3
You cannot have code like this floating about in the class. Only instance variable declarations and static initialiser blocks can be outside methods and constructors.Java Code:public class Roster{ /*System.out.println("Please type in the number of students in your class."); Scanner students=new Scanner(System.in); int intstudents=students.nextLine()-1;*/
Similar Threads
-
difficulties with IF statement condition
By maas in forum JavaServer Pages (JSP) and JSTLReplies: 11Last Post: 10-12-2010, 08:38 AM -
Difficulties with many-to-many association
By berlindutza in forum Web FrameworksReplies: 0Last Post: 03-03-2010, 04:53 PM -
Difficulties using Hibernate + MySQL
By berlindutza in forum Web FrameworksReplies: 3Last Post: 02-17-2010, 09:23 AM -
Difficulties randomizing images in an array
By phb5004 in forum New To JavaReplies: 2Last Post: 12-11-2009, 04:45 AM -
JOptionPane Display Difficulties
By kewlgeye in forum New To JavaReplies: 7Last Post: 05-09-2008, 08:09 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks