Results 1 to 8 of 8
  1. #1
    andnlou2678 is offline Member
    Join Date
    Sep 2011
    Posts
    69
    Rep Power
    0

    Default Buckle My Shoe Java Program

    hi all i have another program i need help with please.

    Write a program to read a number in the range 1 – 10 and output the line from the children’s rhyme “One, two, buckle my shoe”. Assume that the data is valid.


    public class BuckleMyShoe
    {
    public static void main(String[] args)
    {
    int 'i' - (Integer.valueOf( args[0] )).intValue();

    switch ( 'i' )
    {
    case 1:
    System.out.println("One Two Buckle My Shoe");
    break;
    case 3:
    System.out.println("Three Four Kock At The Door");
    break;
    case 5:
    System.out.println("Five Six Pick Up Sticks");
    break;
    case 7:
    System.out.println("Seven Eight Lay Them Straight");
    break;
    case 9:
    System.ou.println("Nine Ten The Big Fat Hen");
    break;
    } // end switch
    } // end main
    } // end of class BuckleMyShoe

    please can some one help me

    many thanks andy..

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Buckle My Shoe Java Program

    Help with what? Ask a specific question, get a specific answer. If you are getting error messages then post them as we don't read minds.

  3. #3
    SRaith is offline Member
    Join Date
    Oct 2011
    Posts
    14
    Rep Power
    0

    Default Re: Buckle My Shoe Java Program

    I commented the quellcode, so, I think it should be clear :P.
    Java Code:
    	public static void main(String[] args)
    	{
    		int i = (Integer.parseInt(args[0]));	// Without '' and -. You have to assign Variable with =
    												// The parseInt method will do the job for you, it will
    												// give you the int value from the String
    		
    		switch ( i )	// 'i' means, its is just a char, but you want to switch through your int variable,
    						// so just put the int variable name there, which means i
    		{
    		case 1:
    			System.out.println("One Two Buckle My Shoe");
    			break;
    		case 3:
    			System.out.println("Three Four Kock At The Door");
    			break;
    		case 5:
    			System.out.println("Five Six Pick Up Sticks");
    			break;
    		case 7:
    			System.out.println("Seven Eight Lay Them Straight");
    			break;
    		case 9:
    			System.out.println("Nine Ten The Big Fat Hen");
    			break;
    		default:	// Just added a default block, it's always a good idea to do that.
    			System.out.println("Wrong number.");
    		} // end switch
    	} // end main

  4. #4
    andnlou2678 is offline Member
    Join Date
    Sep 2011
    Posts
    69
    Rep Power
    0

    Default Re: Buckle My Shoe Java Program

    thank you very much for point this out..

    can you please tell me how to input the code in future so it is easy to read for you..

    many thanks Andy..

  5. #5
    Mr777 is offline Devil
    Join Date
    Nov 2011
    Location
    Pakistan
    Posts
    12
    Rep Power
    0

    Default Re: Buckle My Shoe Java Program

    @SRaith: After appreciating your help, i would suggest you not to spoon feed anyone.
    @andnlou: Be more precise about your errors.

  6. #6
    andnlou2678 is offline Member
    Join Date
    Sep 2011
    Posts
    69
    Rep Power
    0

    Default Re: Buckle My Shoe Java Program

    Java Code:
    public class BuckleMyShoe
    Java Code:
    {
    Java Code:
    public static void main(String[] args)
    Java Code:
    {
    Java Code:
    int i = (Integer.parseInt(args[0]));

    Java Code:
    switch ( i )

    Java Code:
    {
    Java Code:
    case 1:case 2:
    Java Code:
    System.out.println("One Two Buckle My Shoe");
    Java Code:
    break;
    Java Code:
    case 3:case 4:
    Java Code:
    System.out.println("Three Four Kock At The Door");
    Java Code:
    break;
    Java Code:
    case 5:case 6:
    Java Code:
    System.out.println("Five Six Pick Up Sticks");
    Java Code:
    break;
    Java Code:
    case 7:case 8:
    Java Code:
    System.out.println("Seven Eight Lay Them Straight");
    Java Code:
    break;
    Java Code:
    case 9:case 10:
    Java Code:
    System.out.println("Nine Ten The Big Fat Hen");
    Java Code:
    break;
    Java Code:
    default:
    Java Code:
    System.out.println("Wrong number.");
    Java Code:
    }
    Java Code:
    }
    Java Code:
    }
    this is the error code i get back..

    E:\FPT>java BuckleMyShoe
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
    at BuckleMyShoe.main(BuckleMyShoe.java:5)

    What does this mean?

    many thanks Andy..
    Last edited by andnlou2678; 11-10-2011 at 07:28 PM.

  7. #7
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Buckle My Shoe Java Program

    You only need to place the code tags at the start and end of your code. Not around each line.
    Java Code:
    int i = (Integer.parseInt(args[0]));
    I assume this is line 5. You are trying to parse an element from the args array but you did not enter any. You do this on the command line when you launch your program. Or enter them into the arguments property if you are using an IDE.
    Java Code:
    java MyProgram one fish two fish red fish blue fish
    If you do that then the args array will actually contain: {"one", "fish", "two", "fish", "red", "fish", "blue", "fish"}

  8. #8
    andnlou2678 is offline Member
    Join Date
    Sep 2011
    Posts
    69
    Rep Power
    0

    Default Re: Buckle My Shoe Java Program

    thank-you very much for pointing that out i get it now..

    and sorry about code will remember for next time ..

Similar Threads

  1. Call one Java Program from another Java Program
    By rajpalparyani in forum New To Java
    Replies: 3
    Last Post: 02-14-2011, 05:13 AM
  2. execute java program within java program
    By popey in forum New To Java
    Replies: 2
    Last Post: 10-22-2009, 06:32 PM
  3. Replies: 0
    Last Post: 04-04-2008, 03:40 PM
  4. Replies: 0
    Last Post: 10-04-2007, 10:33 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
  •