java 10以内猜字游戏有提示猜中后退出程序
2个回答
展开全部
import java.util.Random;
import java.util.Scanner;
public class pic {
static int number=new Random().nextInt(10)+1;
public static void main(String[] args) {
Guessing();
}
public static void Guessing(){
Scanner s=new Scanner(System.in);
System.out.println("guess:");
int n=s.nextInt();
if(n!=number){
System.out.println("You are wrong.");
Guessing();
}else{
System.out.println("You are right.");
}
}
}
import java.util.Scanner;
public class pic {
static int number=new Random().nextInt(10)+1;
public static void main(String[] args) {
Guessing();
}
public static void Guessing(){
Scanner s=new Scanner(System.in);
System.out.println("guess:");
int n=s.nextInt();
if(n!=number){
System.out.println("You are wrong.");
Guessing();
}else{
System.out.println("You are right.");
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询