nmanpure
June 25th, 2010, 01:55
This is my pick 3 simulator its pretty simple code but its still code. All you do is enter 3 numbers and if they match the random generated numbers then you win......
You can un-comment the " ("The numbers are "+"("+num+", "+numa+", "+numb+")" ); ", doing so will show the the answers so you can cheat.
To play: enter 1 number press space enter another number press space and another number, hit enter.
Or enter 1 number press enter enter another number press enter and another number then press enter.
you dont have to type 1 you can type any number 1-9
here is the code
package lab2b;
import java.util.Scanner;
import java.util.Random;
/**
*
* @author Noah Schweibinz
*/
public class Main
{
public static void main(String[] args)
{
Scanner keybd = new Scanner(System.in);
Random r1 = new Random();
int pick;
int num,numa,numb, num1, num2, num3;
for( ; ; )
{
num = 1 + r1.nextInt(3); //Test
// System.out.println(num); //Test
numa = 1 + r1.nextInt(3); //Test
// System.out.println(numa); //Test
numb = 1 + r1.nextInt(3); //Test
// System.out.println(numb); //Test
System.out.println("Please type three numbers in for your pick 1-9 each: ");
//System.out.println("The numbers are "+"("+num+", "+numa+", "+numb+")" );
num1 = keybd.nextInt();
num2 = keybd.nextInt();
num3 = keybd.nextInt();
if(num1 == num && num2 == numa && num3 == numb)
{
System.out.println("You have won!");
System.out.println("Your Number were: "+num1 + " , " +num2 + " , "+num3 + " , ");
}else
System.out.println("You lose.");
System.out.println("The Loterry numbers were: "+num + " , "+numa + " , "+numb);
System.out.println("You chose: "+ "(" + num1 + ", "+num2+", "+num3+")");
}
}
}
You can un-comment the " ("The numbers are "+"("+num+", "+numa+", "+numb+")" ); ", doing so will show the the answers so you can cheat.
To play: enter 1 number press space enter another number press space and another number, hit enter.
Or enter 1 number press enter enter another number press enter and another number then press enter.
you dont have to type 1 you can type any number 1-9
here is the code
package lab2b;
import java.util.Scanner;
import java.util.Random;
/**
*
* @author Noah Schweibinz
*/
public class Main
{
public static void main(String[] args)
{
Scanner keybd = new Scanner(System.in);
Random r1 = new Random();
int pick;
int num,numa,numb, num1, num2, num3;
for( ; ; )
{
num = 1 + r1.nextInt(3); //Test
// System.out.println(num); //Test
numa = 1 + r1.nextInt(3); //Test
// System.out.println(numa); //Test
numb = 1 + r1.nextInt(3); //Test
// System.out.println(numb); //Test
System.out.println("Please type three numbers in for your pick 1-9 each: ");
//System.out.println("The numbers are "+"("+num+", "+numa+", "+numb+")" );
num1 = keybd.nextInt();
num2 = keybd.nextInt();
num3 = keybd.nextInt();
if(num1 == num && num2 == numa && num3 == numb)
{
System.out.println("You have won!");
System.out.println("Your Number were: "+num1 + " , " +num2 + " , "+num3 + " , ");
}else
System.out.println("You lose.");
System.out.println("The Loterry numbers were: "+num + " , "+numa + " , "+numb);
System.out.println("You chose: "+ "(" + num1 + ", "+num2+", "+num3+")");
}
}
}