Results 1 to 7 of 7
  1. #1
    swedishfished is offline Member
    Join Date
    Sep 2012
    Posts
    42
    Rep Power
    0

    Default Eclipse won't run program?

    This is just a thing I made for my friend who doesn't know what WoW character to play on.

    I don't get any errors, here is the code
    Java Code:
    import java.util.Random;
    import java.util.Scanner;
    class apples {
    	public static void main(String args[]){
    		Random dice = new Random();
    		Scanner input = new Scanner(System.in);
    		int numberofclasses;
    		numberofclasses=input.nextInt();
    		System.out.print("Number of classes is" +numberofclasses);
    		String classes[]= new String[numberofclasses];
    		for(int count=0; count<classes.length; count++){
    			System.out.println("Type class number" + count);
    			classes[count]=input.nextLine();
    			System.out.println(classes[count]);
    
    		}
    		int number=dice.nextInt();
    		number=number%classes.length;
    		System.out.println(classes[number]);
    	}	
    }

  2. #2
    Arbalest is offline Member
    Join Date
    Sep 2012
    Posts
    11
    Rep Power
    0

    Default Re: Eclipse won't run program?

    it's obvious you can't use a variable as an array delimiter, it need to be a constant so this is fail :
    Java Code:
    int numberofclasses;
            numberofclasses=input.nextInt();
    try it this way
    Java Code:
    final int numberofclasses =10;//whatever you want

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default Re: Eclipse won't run program?

    Quote Originally Posted by Arbalest View Post
    it's obvious you can't use a variable as an array delimiter
    What's an 'array delimiter'?

    Nothing wrong with using an int variable to specify an array size at declaration.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default Re: Eclipse won't run program?

    Quote Originally Posted by swedishfished View Post
    I don't get any errors
    So what's your question?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    swedishfished is offline Member
    Join Date
    Sep 2012
    Posts
    42
    Rep Power
    0

    Default Re: Eclipse won't run program?

    When i click 'run,' nothing happens, but there are no errors in the code, or at least none that eclipse shows me

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default Re: Eclipse won't run program?

    Stick a System.out.println(...) right at the top of your main(...) method, between lines 4 and 5 of your posted code, and see if that prints. Report back here.

    Also, go through Code Conventions for the Java Programming Language: Contents -- a class name should start with an uppercase letter.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    SJF
    SJF is offline Senior Member
    Join Date
    Oct 2012
    Posts
    108
    Rep Power
    0

    Default Re: Eclipse won't run program?

    Eclipse is probably running your program. Without an output prior to first input, the console window may not show... switch to debug view, or prompt for input prior to your input.nextInt();

Similar Threads

  1. Program running in eclipse but JAR won't run?
    By Jma84 in forum New To Java
    Replies: 4
    Last Post: 08-13-2012, 12:52 PM
  2. Need help with java program using eclipse
    By starplayerrob in forum New To Java
    Replies: 16
    Last Post: 07-01-2011, 10:34 AM
  3. I cant run the program outside eclipse, why?
    By kokorini in forum New To Java
    Replies: 4
    Last Post: 07-02-2010, 11:46 PM
  4. A tab in an eclipse RCP program
    By Drun in forum Eclipse
    Replies: 0
    Last Post: 05-20-2010, 04:56 PM
  5. DB program in Eclipse
    By Unni in forum Eclipse
    Replies: 3
    Last Post: 08-10-2007, 12:07 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
  •