Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[Source Code] My Java Dice Roller.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
ravicus
Master Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 464

PostPosted: Mon Mar 19, 2007 2:57 pm    Post subject: [Source Code] My Java Dice Roller. Reply with quote

Hey guys, I just programmed this Java dice roller after reading about loops in my book, please comment.
Code:
//Imports
import java.util.Random;
import java.util.Scanner;
import static java.lang.System.out;
 
public class diceroller {
   
    public static void main(String[] args) {
    //Declarations
    int die1 = 0;
       int die2 = 0;
          int mynumber = 0;
          int timesrolled = 0;
             Random randomizer = new Random();
                Scanner s = new Scanner(System.in);
                //Begin Main Code
                
                //Ask the user for a number
                out.print ("Please enter a number 2-12 for the two dice to roll: ");
                mynumber = (s.nextInt());
                //User error checking loop
                while ((mynumber) > 12 || (mynumber) < 2) {
                      out.println ("You entered an invalid number.");
                      out.print ("Please enter a number 2-12 for the two dice to roll: ");
                mynumber = (s.nextInt());
                }
                out.println ("Thank-you, let the dice rolling begin!");
                //Start the dice rolling loop
                while ((die1) + (die2) != (mynumber)) {
                   die1 = randomizer.nextInt(6) + 1;
                   die2 = randomizer.nextInt(6) + 1;
                   
                   out.print (die1);
                   out.print (" ");
                   out.println (die2);
                   timesrolled++;
                   }
                   //Ending Message
                   out.print ("Successfully rolled ");
                   out.print (mynumber);
                   out.print (" in ");
                      out.print (timesrolled);
                      out.print (" rolls");
                
          
    }
}

_________________
Back to top
View user's profile Send private message
DeltaFlyer
Grandmaster Cheater
Reputation: 0

Joined: 22 Jul 2006
Posts: 666

PostPosted: Mon Mar 19, 2007 4:00 pm    Post subject: Reply with quote

Use Math.random()

and you really should get your indentations right.

_________________

Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for?
Back to top
View user's profile Send private message
ravicus
Master Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 464

PostPosted: Mon Mar 19, 2007 4:29 pm    Post subject: Reply with quote

Whats math.random?
Why should i get my indentations right when the program i use shows me where they are.

_________________
Back to top
View user's profile Send private message
DeltaFlyer
Grandmaster Cheater
Reputation: 0

Joined: 22 Jul 2006
Posts: 666

PostPosted: Mon Mar 19, 2007 5:01 pm    Post subject: Reply with quote

ravicus wrote:
Whats math.random?


Look it up: http://java.sun.com/j2se/1.4.2/docs/api/

Quote:
Why should i get my indentations right when the program i use shows me where they are.


Because you're posting this on the internet for OTHER people to read? Make your programs readable with the PROPER indentations. A simple F2 does it in Ready to Program:

Code:

//Imports
import java.util.Random;
import java.util.Scanner;
import static java.lang.System.out;

public class diceroller
{

    public static void main (String[] args)
    {
        //Declarations
        int die1 = 0;
        int die2 = 0;
        int mynumber = 0;
        int timesrolled = 0;
        Random randomizer = new Random ();
        Scanner s = new Scanner (System.in);
        //Begin Main Code

        //Ask the user for a number
        out.print ("Please enter a number 2-12 for the two dice to roll: ");
        mynumber = (s.nextInt ());
        //User error checking loop
        while ((mynumber) > 12 || (mynumber) < 2)
        {
            out.println ("You entered an invalid number.");
            out.print ("Please enter a number 2-12 for the two dice to roll: ");
            mynumber = (s.nextInt ());
        }
        out.println ("Thank-you, let the dice rolling begin!");
        //Start the dice rolling loop
        while ((die1) + (die2) != (mynumber))
        {
            die1 = randomizer.nextInt (6) + 1;
            die2 = randomizer.nextInt (6) + 1;

            out.print (die1);
            out.print (" ");
            out.println (die2);
            timesrolled++;
        }
        //Ending Message
        out.print ("Successfully rolled ");
        out.print (mynumber);
        out.print (" in ");
        out.print (timesrolled);
        out.print (" rolls");


    }
}

_________________

Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for?
Back to top
View user's profile Send private message
ravicus
Master Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 464

PostPosted: Mon Mar 19, 2007 7:12 pm    Post subject: Reply with quote

Ready to program costs money...
_________________
Back to top
View user's profile Send private message
DeltaFlyer
Grandmaster Cheater
Reputation: 0

Joined: 22 Jul 2006
Posts: 666

PostPosted: Mon Mar 19, 2007 7:35 pm    Post subject: Reply with quote

ravicus wrote:
Ready to program costs money...


I would find the link and post it if I could, but I downloaded it from an unlinked page on my school's website a year ago and my teacher removed the link from our messaging system.

Plus, I'm pretty sure that other programs have similar functions, just well hidden as they TRY to make it automatic. For example, the format shortcut in VS2005 is Ctrl + K + F.

_________________

Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for?
Back to top
View user's profile Send private message
ravicus
Master Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 464

PostPosted: Mon Mar 19, 2007 8:07 pm    Post subject: Reply with quote

Ok, I'll look for it in JCreator.
_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites