Here is the program for predicting the number which was selected by the user
Lets try this on your PC........
First of all user has to select one number between 1 and 15.Then program will start prediction.
Finally program will predict and print the selected number
import java.io.*;
class Game
{
public static void main(String args[]) throws IOException
{
int[] a1={8,9,10,11,12,13,14,15};
int[] a2={4,5,6,7,12,13,14,15};
int[] a3={2,3,6,7,10,11,14,15};
int[] a4={1,3,5,7,9,11,13,15};
DataInputStream din=new DataInputStream(System.in);
String str=new String();
System.out.println("choose one number from 1 to 15");
System.out.println("is your choosen number present in below list enter 1 else enter 0:");
for(int j=0;j<8;j++)
{System.out.print(" "+a1[j]);
}
System.out.println(" ");
str=str+din.readLine();
System.out.println("is your choosen number present in below list enter 1 else enter 0:");
for(int j=0;j<8;j++)
{System.out.print(" "+a2[j]);
} System.out.println(" ");
str=str+din.readLine();
System.out.println("is your choosen number present in below list enter 1 else enter 0:");
for(int j=0;j<8;j++)
{System.out.print(" "+a3[j]);
} System.out.println(" ");
str=str+din.readLine();
System.out.println("is your choosen number present in below list enter 1 else enter 0:");
for(int j=0;j<8;j++)
{System.out.print(" "+a4[j]);
} System.out.println(" ");
str=str+din.readLine();
number(str);
}
static void number(String str)
{
int num=Integer.parseInt(str);
int temp=num;
int i=0;
while(temp>0)
{
i++;
temp=temp/10;
}int k=0; int dec=0;
while(num>0)
{
int rem=num%10;
dec=dec+rem*pow(2,k);
k++;
num=num/10;
}
System.out.println("your selected number is"+dec);
}
static int pow(int a,int b)
{
if(b==0)
{return(1);}
else{return(a*pow(a,b-1));}
}
}
OUTPUT of the above game is
Lets try this on your PC........
First of all user has to select one number between 1 and 15.Then program will start prediction.
Finally program will predict and print the selected number
import java.io.*;
class Game
{
public static void main(String args[]) throws IOException
{
int[] a1={8,9,10,11,12,13,14,15};
int[] a2={4,5,6,7,12,13,14,15};
int[] a3={2,3,6,7,10,11,14,15};
int[] a4={1,3,5,7,9,11,13,15};
DataInputStream din=new DataInputStream(System.in);
String str=new String();
System.out.println("choose one number from 1 to 15");
System.out.println("is your choosen number present in below list enter 1 else enter 0:");
for(int j=0;j<8;j++)
{System.out.print(" "+a1[j]);
}
System.out.println(" ");
str=str+din.readLine();
System.out.println("is your choosen number present in below list enter 1 else enter 0:");
for(int j=0;j<8;j++)
{System.out.print(" "+a2[j]);
} System.out.println(" ");
str=str+din.readLine();
System.out.println("is your choosen number present in below list enter 1 else enter 0:");
for(int j=0;j<8;j++)
{System.out.print(" "+a3[j]);
} System.out.println(" ");
str=str+din.readLine();
System.out.println("is your choosen number present in below list enter 1 else enter 0:");
for(int j=0;j<8;j++)
{System.out.print(" "+a4[j]);
} System.out.println(" ");
str=str+din.readLine();
number(str);
}
static void number(String str)
{
int num=Integer.parseInt(str);
int temp=num;
int i=0;
while(temp>0)
{
i++;
temp=temp/10;
}int k=0; int dec=0;
while(num>0)
{
int rem=num%10;
dec=dec+rem*pow(2,k);
k++;
num=num/10;
}
System.out.println("your selected number is"+dec);
}
static int pow(int a,int b)
{
if(b==0)
{return(1);}
else{return(a*pow(a,b-1));}
}
}
OUTPUT of the above game is
0 comments:
Post a Comment