-
November 23rd, 2013, 03:51 AM
#1
Need help with how to put code in method
Hi, i am using Eclipse. I made a game as part of my assignment but I am confused on how i can write this code in a method
Code:
if (playerPosition % 2 == 0){
System.out.println("You are now on step number " +playerPosition);
} else if (playerPosition % 2 != 0){
System.out.println("You landed on an odd number! You must move 5 steps back");
playerPosition = playerPosition - 5;
System.out.println("You are now on step number " +playerPosition);
}
cpuRoll = cpuRoll();
System.out.println("The computer rolled "+cpuRoll);
cpuPosition = cpuPosition + cpuRoll;
if (cpuPosition % 2 != 0){
System.out.println("The computer is now on step number " +cpuPosition);
} else if(cpuPosition % 2 == 0){
System.out.println("The computer landed on an even number! The computer moved 5 steps back");
cpuPosition = cpuPosition - 5;
System.out.println("The computer is now on step number " +cpuPosition);
System.out.println();
}
Any help will be appreciated
-
November 23rd, 2013, 02:15 PM
#2
Re: Need help with how to put code in method
I'm not quite sure what you are asking here
-
November 23rd, 2013, 03:24 PM
#3
Re: Need help with how to put code in method
basically the code i just provided is in my main method. I need help with how i can put it in a method so i can call it from my main method
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|