这串猜数字的JAVA小游戏源代码在netbeans7.0软件上应该创建哪个项目运行? 10
我不懂JAVAME,但是想把它运行出来,具体怎么操作?用netbeans7.0软件。从打开netbeans7.0软件到粘贴代码的一系列步骤说一下啊.importjava....
我不懂JAVA ME,但是想把它运行出来,具体怎么操作?用netbeans7.0软件。从打开netbeans7.0软件到粘贴代码的一系列步骤说一下啊.
import java.util.Random;
import java.util.Scanner;
public class GuessNumber {
private int guessNumber = 0;
public GuessNumber(){
createNumber();
}
private void createNumber(){
Random random = new Random();
guessNumber=random.nextInt(100);
}
private void guess(){
long startTime = System.currentTimeMillis();
int counter = 0;
Scanner scanner = new Scanner(System.in);
int number = 0;
while(true){
System.out.print("请输入您要猜的数字:");
number = scanner.nextInt();
counter++;
if(guessNumber==number){
break;
}
if(number>guessNumber){
System.out.println("系统提示!您猜的数字偏大!");
}else{
System.out.println("系统提示!您猜的数字偏小!");
}
}
long endTime = System.currentTimeMillis();
System.out.println("您总共猜了"+counter+"次");
System.out.println("您总共花了"+(endTime-startTime)+"毫秒的世间答对正确答案!");
}
public static void main(String[] args) {
new GuessNumber().guess();
}
} 展开
import java.util.Random;
import java.util.Scanner;
public class GuessNumber {
private int guessNumber = 0;
public GuessNumber(){
createNumber();
}
private void createNumber(){
Random random = new Random();
guessNumber=random.nextInt(100);
}
private void guess(){
long startTime = System.currentTimeMillis();
int counter = 0;
Scanner scanner = new Scanner(System.in);
int number = 0;
while(true){
System.out.print("请输入您要猜的数字:");
number = scanner.nextInt();
counter++;
if(guessNumber==number){
break;
}
if(number>guessNumber){
System.out.println("系统提示!您猜的数字偏大!");
}else{
System.out.println("系统提示!您猜的数字偏小!");
}
}
long endTime = System.currentTimeMillis();
System.out.println("您总共猜了"+counter+"次");
System.out.println("您总共花了"+(endTime-startTime)+"毫秒的世间答对正确答案!");
}
public static void main(String[] args) {
new GuessNumber().guess();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询