Want to see a majic Trick?

Here is a bit of Java Majic,,,
Copy and paste this Code into a text editor and run it as a java app

… pretty cool huh?

________________________________________________________

//———————————————————————
// class.homework4 Author: Trevor Slade
//———————————————————————

import java.util.Scanner;
import java.util.Random;

public class homework4 {
public static void main (String[] args){

// Create All variables
int i;
int j;
int k;
int l;
int m;
int n;
int o;
int p;
int q;
int r;
int s;
int t;
int u;
int v;
int w;

int number;
int rand1;
int rand2;
int rand3;
int rand4;
int rand5;

String one;
String two;
String three;
String four;
String five;
String again;

Scanner scan = new Scanner (System.in);
Random gen = new Random ();

System.out.println(” Answer all questions with YES or NO !”);
System.out.println(” Do you want to play?”);
again = scan.nextLine();

while (again.equals(“YES”))
{
number=0;
i=1;
j=0;
k=2;
l=0;
m=4;
n=0;
o=8;
p=0;
q=16;
r=0;

rand1 = gen.nextInt(2);
rand2 = gen.nextInt(2);
rand3 = gen.nextInt(2);
rand4 = gen.nextInt(2);
rand5 = gen.nextInt(2);
// While loop to create the first set of numbers
while (i<=31)
{
if (rand1==1)
{
s = 31-i;
System.out.print (s +" ");
}
else
{
System.out.print (i +" ");
}

i=i+2;
// j is an iterative counter
j=j+1;

if (j%4==0)

{
System.out.print("\n");

}

}

System.out.println(" Is your number contained in this set of numbers? ");
one = scan.nextLine();

System.out.println("\n\n");
// While loop to create the second set of numbers

while (k<=31)
{

if (rand2==1)
{
t = 31-k;
System.out.print (t +" ");
}
else
{
System.out.print (k +" ");
}
//l is an iterative counter
l=l+1;

if (l%2==0)
{
k=k+3;}

else {
k=k+1;
}

if (l%4==0)

{
System.out.print("\n");
}

}

System.out.println(" Is your number contained in this set of numbers? ");
two = scan.nextLine();
System.out.println("\n\n");
// While loop to create the third set of numbers

while (m<=31)
{

if (rand3==1)
{
u = 31-m;
System.out.print (u +" ");
}
else
{
System.out.print (m +" ");
}

// n is an iterative counter
n=n+1;

if (n%4 == 0)
{
System.out.print ("\n");
m=m+5;

}
else
{
m=m+1;

}

}

System.out.println(" Is your number contained in this set of numbers? ");
three = scan.nextLine();
System.out.println("\n\n");

// While loop to create the fourth set of numbers

while (o<=31)
{

if (rand4==1)
{
v = 31-o;
System.out.print (v +" ");
}
else
{
System.out.print (o +" ");
}

// p is an iterative counter
p=p+1;
if (p%8==0)
{
o=o + 9;

}

else
{
o=o+1;
}

if (p%4==0)

{
System.out.print("\n");
}

}

System.out.println(" Is your number contained in this set of numbers? ");
four = scan.nextLine();

// while loop for the fifth set of numbers

System.out.println("\n\n");
while (q<=31)
{
if (rand5==1)
{
w = 31-q;
System.out.print (w +" ");
}
else
{
System.out.print (q +" ");
}
q=q+1;

// r is an iterative counter
r=r+1;

if (r%4 == 0)
{
System.out.print("\n");
}
}

System.out.println(" Is your number contained in this set of numbers? ");
five = scan.nextLine();

if (one.equals("YES")&& rand1==0 || one.equals("NO")&& rand1==1)
{
number= number + 1;

}
if (two.equals("YES")&& rand2==0 || two.equals("NO")&& rand2==1)
{
number = number + 2;
}
if (three.equals("YES")&& rand3==0 || three.equals("NO")&& rand3==1)
{
number = number +4;
}
if (four.equals("YES")&& rand4==0 || four.equals("NO")&& rand4==1)
{
number =number+8;
}
if (five.equals("YES")&& rand5==0 || five.equals("NO")&& rand5==1)
{
number = number + 16;
}

System.out.println(one);
System.out.println ("Your number was: " +number);
System.out.println ("Do you want to play again?");
again = scan.nextLine();

}

}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: