猜数字
package guess;
import java.util.Scanner;
public class guess {
public static void main(String[] args) {
int i = (int)(Math.random()*99+1);
System.out.print("请猜一个1-100的数字:");
Scanner scanner = new Scanner(System.in);
int a;
int score=0,k;
for(k=0;k<10;k++){
a = scanner.nextInt();
if(i==a){
System.out.println("恭喜你猜对了!");
i = (int)(Math.random()*99+1);
score+=10;
System.out.print("请猜一个1-100的数字:");
}
else{
if(a>i){
System.out.println("你猜的数有点大。。。");
}
if(a<i){
System.out.println("你猜的数有点小。。。");
}
}
}
System.out.println("你的得分是:"+score+"!");
}
}
package guess;
import java.util.Scanner;
public class guess {
public static void main(String[] args) {
int i = (int)(Math.random()*99+1);
System.out.print("请猜一个1-100的数字:");
Scanner scanner = new Scanner(System.in);
int a;
int score=0,k;
for(k=0;k<10;k++){
a = scanner.nextInt();
if(i==a){
System.out.println("恭喜你猜对了!");
i = (int)(Math.random()*99+1);
score+=10;
System.out.print("请猜一个1-100的数字:");
}
else{
if(a>i){
System.out.println("你猜的数有点大。。。");
}
if(a<i){
System.out.println("你猜的数有点小。。。");
}
}
}
System.out.println("你的得分是:"+score+"!");
}
}