|
import java.io.*;<br>import java.lang.Math.*;<br>import java .*;<br><br>class RandNum{<br> public static void randnum(int[] num){<br> for(int i=0;i<4;i++){<br> num=(int)(Math.random()*10);<br> for(int j=0;j<i;j++){<br> if(num==num[j]){<br> num=(int)(Math.random()*10);<br> j=-1;<br> } <br> }<br> }<br> return;<br> }<br>}<br> <br>public class pingou{<br> public static void main(String[] args) throws IOException{<br> int[] num=new int[4],g=new int[4];<br> int count=0,guess,a,b;<br> BufferedReader stdin= new BufferedReader( new InputStreamReader(System.in));<br> String ok;<br> RandNum.randnum(num);<br> //for(int i=0;i<4;i++)<br> // System.out.print(num);<br> //System.out.println("n");<br> do{ <br> do{ a=0;b=0;<br> System.out.println("Enter the number0000-9999)");<br> guess=Integer.parseInt(stdin.readLine());<br> if(guess>9876||guess<0123){<br> System.out.println("Error number!~~ ");<br> System.exit(1);<br> }<br> for(int i=3;i>=0;i--){<br> g=guess%10;<br> guess/=10;<br> for(int j=3;j>i;j--){<br> if(g==g[j]){<br> System.out.println("repeated number!~~");<br> System.exit(1);<br> }<br> }<br> }<br> <br> for(int m=0;m<4;m++){<br> for(int n=0;n<4;n++)<br> if(g[n]==num[m]){<br> if(n==m) a++;<br> else b++;<br> }<br> }<br> System.out.println((count+1) +"."+ a +"A" +b +"B");<br> if(a==4){<br> System.out.println("great,you get it!");<br> System.exit(1);<br> }<br> }while(count++<7);<br> System.out.println("You failed to guess it.");<br> System.out.println("The number is: "+num[0]+num[1]+num[2]+num[3]);<br> System.out.println("Would you like to play again?(y or n)");<br> ok=stdin.readLine();<br> if(ok.equals("n")) System.exit(1);<br> }while(true); <br> }<br>} |
|