ney ha..kalau nak taw apa yang kami blajar lam ISA...
yang ney...
one of the example laa...
tyme tgah2 check folder..
..terjumpa laa folder yang ade "benda" yang pernah buat aku sangat tension hari tu ney..
try dis..using netbean@blueJ...
hehe...
this is one of the assignment that we've gtten ;)
1. Number Puzzle : Users task is to guess 4 digits generated by your program. Those digits should be unique. Your program will be given hint to users based on their guess.
Number of Green – Right digit at the right place
Number of Red – Right digit but at the wrong place
For example :
Number generated is 4589
User guess is 4810
Hint: 1 Green 1 Red
Use Netbeans for the assignment
and..this is my answer..hahha. . .
(tak taw laa betul ke tak ape yg aku coding merepek2 tu)
but at least,,I've completed the assignmnent!
bila daa siap tu..fuh..
what a relief..!
;)
/**
* ASSIGNMENT INI SANGAT PENING KPALA~
*
* SITI AISYAH BINTI HALIM
* 1100028
*/
import java.util.InputMismatchException;
import java.util.Random;
import java.util.Scanner;
public class GuessFourDigits
{
public static void main(String[] args){
Random gen= new Random();
int digits= 0;
while(hasDupes(digits =(int) (Math.random()*9000) + 1000));
String digitsStr = digits +"";
boolean guessed = false;
Scanner input = new Scanner(System.in);
int guesses = 0;
do{
int GREEN = 0;
int RED = 0;
System.out.print("Lets Play Guessing Numbers with Us..!");
System.out.print("Guess 4-input number >>from 1000-9999<<>
int guess;
try{
guess = input.nextInt();
if(hasDupes(guess) || guess <>
}catch(InputMismatchException e){
continue;
}
guesses++;
String guessStr = guess + "";
for(int i= 0;i <>
if(guessStr.charAt(i) == digitsStr.charAt(i)){
GREEN++;
}else if(digitsStr.contains(guessStr.charAt(i)+"")){
RED++;
}
}
if(GREEN == 4){
guessed = true;
}else{
System.out.println(RED+" RED and "+GREEN+" GREEN.");
}
}while(!guessed);
System.out.println("Excellent..! You guess is CORRECT after "+guesses+" guesses!");
}
public static boolean hasDupes(int num){
boolean[] digs = new boolean[10];
while(num > 0){
if(digs[num%10]) return true;
digs[num%10] = true;
num/= 10;
}
return false;
}
}
..tapi jgan laa sebab coding yang pelik ney...
..korang jady tak minat ngan ISA...
..best kos ney oke..
till we meet again!