上源码:
import java.util.Scanner;
class DemoTest
{
public static void main(String[] a)
{
int i=0;
int da=0;
int xiao=0;
int random=(int)(Math.random()*100+1);
//System.out.print(random);
System.out.print("猜一下,是多少(1-100):");
int count=1;
int[] getArray = new int[]{0,0,0,0,0,0,0};
while(true)
{
Scanner sc = new Scanner(System.in);
int getNum = sc.nextInt();
if(getNum<1||getNum>100)
{
System.out.print("您输入不再范围,重新输入:");
continue;
}
getArray[i]=getNum;
i++;
if(i>1)
{
/*if(getArray[i-2]==getArray[i-1])
{
System.out.println("你是猪吗?都告诉你不对,还输入相同的数");
System.out.print("重新输入:");
i--;
continue;
}*/
if(getArray[i-2]>random&&getArray[i-1]>=getArray[i-2])
{
i--;
da++;
if(da>2)
{
System.out.println("哥们你疯了,没法沟通!不玩了!");
break;
}
System.out.println("偏大偏大!!!都告诉你值偏大");
System.out.print("重新输入:");
continue;
}
if(getArray[i-2]<random&&getArray[i-1]<=getArray[i-2])
{
i--;
xiao++;
if(xiao>2)
{
System.out.println("哥们你疯了,没法沟通!不玩了!");
break;
}
System.out.println("你是猪吗?都告诉你值偏小");
System.out.print("重新输入:");
continue;
}
}
if(getNum!=random)
{
if(count>5)
{
System.out.println("智商真低,还是回家养猪吧!答案是:"+getNum);
break;
}
if(getNum>random)
{
System.out.println("您猜的值是"+getNum+",值偏大,请重猜!");
}
else
{
System.out.println("您猜的值是"+getNum+",值偏小,请重猜!");
}
}
else
{
System.out.println("恭喜您猜对了!答案是:"+getNum);
}
count++;
System.out.print("请输入:");
}
}
}
后面学了打包,我尝试改成exe文件。
好激动,终于自己写代码了
|
|