所以我刚开始学习Java,它的字面意思就像我的第一天,我想尝试做一个coinflip游戏。我已经知道了大量的Javascript,所以我试图将这些知识应用到Java。所以,除了一件事情之外,所有事情都一直在努力:提示用户进行选择。所以在线阅读,我必须导入扫描仪,所以我做到了,因为你可以从我的代码中看到。我也尝试了一些代码,你可以让用户导入一个字符串,但你可以稍后在我的程序中看到我将变量userChoice更改为一个数字。所以基本上我只需要帮助。如果有某种方法可以存储一个可以存储数字或字符串的变量类型,那么这种方法最好。但即时通讯开放给其他方式做到这一点!先谢谢了!这里是代码:你如何提示用户输入java
package test;
import java.util.Scanner;
public class testclass {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("hi");
int bob;
bob = (int) Math.floor(Math.random()*2);
System.out.println(bob);
System.out.println("Enter heads or tails?");
System.out.println("You entered "+ userChoice);
if (bob == 0) {
System.out.println("Computer flipped heads");
}
else {
System.out.println("Computer flipped tails");
}
if(userChoice == "Heads") {
userChoice = 0;
}
else {
userChoice = 1;
}
if (userChoice == bob) {
System.out.println("You win!");
}
else {
System.out.println("Sorry you lost!")
}
}
}
哦是的顺便说一句,你可以看到,我经常提到userChoice,这就是我想要的无论什么商店用户导入的变量名称! – 2014-11-07 02:44:07
通过导入,你的意思是输入文字?这通常被称为“输入”,“导入”是一个非常不同的东西? – Pokechu22 2014-11-07 02:44:39
哦,好吧,对不起,这就是我的意思,我不是一个非常好的程序员,但XP。有时我的终结者有点偏离! – 2014-11-07 03:28:32