Need help with how to put code in method
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Need help with how to put code in method

  1. #1
    Join Date
    Nov 2013
    Posts
    2

    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

  2. #2
    Join Date
    Jun 2013
    Location
    New York, USA
    Posts
    21

    Re: Need help with how to put code in method

    I'm not quite sure what you are asking here

  3. #3
    Join Date
    Nov 2013
    Posts
    2

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center