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..
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.
Re: Buckle My Shoe Java Program
I commented the quellcode, so, I think it should be clear :P.
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
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..
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.
Re: Buckle My Shoe Java Program
Code:
public class BuckleMyShoe
Code:
public static void main(String[] args)
Code:
int i = (Integer.parseInt(args[0]));
Code:
System.out.println("One Two Buckle My Shoe");
Code:
System.out.println("Three Four Kock At The Door");
Code:
System.out.println("Five Six Pick Up Sticks");
Code:
System.out.println("Seven Eight Lay Them Straight");
Code:
System.out.println("Nine Ten The Big Fat Hen");
Code:
System.out.println("Wrong number.");
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..
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.
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.
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"}
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 ..