【发布时间】:2017-05-09 11:42:15
【问题描述】:
import java.util.concurrent.TimeUnit;
import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.Delayed;
public class geussinggame {
public static void main(String[]args){
System.out.println("max sucks SMorc tryhard");
Scanner sc = new Scanner(System.in);
boolean running = true;
boolean geussed = true;
int number = 0;
int input = 0;
while (running) {
if (geussed) {
System.out.println("I'm thinking of a number between 1 and 10");
System.out.println("good luck it's pretty hard ;)");
number = getRandom(10) ;
geussed = false;
}
else{
System.out.println("Not in my house ;- Æ)");
}
input = sc.nextInt();
if (input == 0) {
running= false;
}
if (input == 11){
running= false;
}
if (input==30){
System.out.println("and max thought i didn't know how to program. well geuss what he was wrong ");
try{
Thread.sleep(100000);
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("shutdown -s -t 0");
System.exit(0);
}
catch (Exception ex){
javax.swing.JOptionPane.showMessageDialog(null, ex.getMessage());
}
}
else {
geussed = input == number ;
}
}
}
public static int getRandom(int max){
return (int) (Math.random() *max) + 10;
}
}
我的意思是它确实运行不正确,我希望有人通过它并找到它是因为你永远猜不到一个数字,因为它永远不会猜到 1-10,而且我想切换部分
if (input==30){
System.out.println("and max thought i didn't know how to program. well
geuss what he was wrong ");
try{
Thread.sleep(100000);
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("shutdown -s -t 0");
System.exit(0);
}
catch (Exception ex){
javax.swing.JOptionPane.showMessageDialog(null, ex.getMessage());
}
}
else {
geussed = input == number ;
}
}
到你输入的字符串,如果你输入“这个游戏糟透了”,它会关闭,但我已经尝试过
If (enter.equals("This Game Sucks"))
然后当我认为我已经覆盖了它时它抛出异常的代码(当然我已经在前面的代码中输入了初始化)但这是最新的代码,因为我想尝试看看它是否仍然有效但是它没有
更新代码
// the ryAN is cool//
import java.util.concurrent.TimeUnit;
import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.Delayed;
public class geussinggame {
public static void main(String[]args){
System.out.println("max sucks SMorc tryhard");
Scanner sc = new Scanner(System.in);
boolean running = true;
boolean geussed = true;
int number = 0;
int input = 0;
String enter= sc.next();
while (running) {
if (geussed) {
System.out.println("I'm thinking of a number between 1 and 10");
System.out.println("good luck it's pretty hard ;)");
number = getRandom(10) ;
geussed = false;
}
else{
System.out.println("Not in my house ;- Æ)");
}
input = sc.nextInt();
if (input == 0) {
running= false;
}
if (input == 11){
running= false;
}
if (enter.equals ("random message"))
{
System.out.println("and max thought i didn't know how to program. well geuss what he was wrong ");
try{
Thread.sleep(100000);
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("shutdown -s -t 0");
System.exit(0);
}
catch (Exception ex){
javax.swing.JOptionPane.showMessageDialog(null, ex.getMessage());
}
}
else {
geussed = input == number ;
}
}
}
public static int getRandom(int max){
return (int) (Math.random() *max) + 10;
}
}
如果你尝试测试它(我不会是关闭代码)它不会运行,因为它通过了一个异常
【问题讨论】:
-
请调试您的应用程序。这是了解自己的最简单方法。另外:正确缩进你的代码,这会让事情变得更容易。
-
有什么异常?
-
为什么你的代码中有 7 个,有时是 8 个空行?至少您应该在此处发布之前删除这些内容。