Game Tebak Angka

June 6, 2010 at 12:07 pm Leave a comment

public static void main(String[] args)throws IOException {

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

int[] InputAngka= new int[11];

int x=0;

int AngkaRahasia = (int)(Math.random()*((10-0+1)+0));

System.out.println(“Tebak angka x (angka 0 sampai 10) :”);

do{

if (x<=4)

{

System.out.print(“Masukkan Angka Prediksi Anda “+ (x+1) +”: “);

InputAngka[x]= Integer.parseInt(br.readLine());

//Check data sama dengan angka rahasia dengan memasukkan data prediksi dan data rahasia untuk dicheck

if (checkBenarJawaban(AngkaRahasia,InputAngka[x])==false)

{

System.out.println(“Prediksi Anda SALAH”);

}else

{

System.out.println(“Prediksi Anda Benar”);

System.out.println(“Angka rahasia : ” + AngkaRahasia);

//menampilkan data prediksi dengan memanggil Procedure tampilDataPrediksi

tampilDataPrediksi(InputAngka,x);

}

}else

{              System.out.println(“Anda KALAH, Maksimal prediksi 5 kali”);

System.out.println(“Angka rahasia : ” + AngkaRahasia);

//menampilkan data prediksi dengan memanggil Procedure tampilDataPrediksi

tampilDataPrediksi(InputAngka,x-1);

InputAngka[x]=AngkaRahasia;}

x+=1;

}while(AngkaRahasia!=InputAngka[x-1]);

}

//Funtion

static boolean checkBenarJawaban(int prediksi, int angkarahasia)

{          if (prediksi==angkarahasia)

{

return true;

}else

return false;

}

//Procedure

static void tampilDataPrediksi(int[] prediksi,int jumlahprediksi)

{

System.out.println(“Prediksi Anda”);

for (int y=0;y<=jumlahprediksi;y++)

{

System.out.print(prediksi[y]+”\t”);

}}}

Advertisement

Entry filed under: Uncategorized. Tags: .

Fibonanci

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 )

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

Trackback this post  |  Subscribe to the comments via RSS Feed


 

June 2010
M T W T F S S
« Jan    
 123456
78910111213
14151617181920
21222324252627
282930  

Pages

Recent Posts


Blogger Ngalam



helga indra:



Follow

Get every new post delivered to your Inbox.