String 它们是用户输入一个单词并将该单词变成a的一种方式吗?
我正在尝试创建角色2骰子的程序。然后,用户选择“是”再次扮演骰子角色,或选择“否”停止掷骰子String 它们是用户输入一个单词并将该单词变成a的一种方式吗?,string,while-loop,user-input,java.util.scanner,String,While Loop,User Input,Java.util.scanner,我正在尝试创建角色2骰子的程序。然后,用户选择“是”再次扮演骰子角色,或选择“否”停止掷骰子 import java.util.*; public class Dice { public static void main(String[] args) { Random dice1 = new Random(); Scanner in = new Scanner(System.in); //varib
import java.util.*;
public class Dice
{
public static void main(String[] args)
{
Random dice1 = new Random();
Scanner in = new Scanner(System.in);
//varibles
int die1;
int die2;
byte playagain=1;
byte Yes = 1;
byte No = 0;
int total;
int stop = 0;
//Want find I way to change words into #s
String start = Yes;
while(stop<5 && start<Yes){
stop+=1;
die1=dice1.nextInt(6)+1;
die2=dice1.nextInt(6)+1;
total=die1 + die2;
System. out. println("You rolled a " + total+ ".");
System. out. println("Do you want to play again?");
System. out. println("Type Yes to keep playing you and No to stop.");
/*I want people to be able to input Yes and that equal a # so I can use it in the While loop. Same with No.*/
start=in.next();
System. out. println("start is at " + start);
}
}
}
import java.util.*;
公共类骰子
{
公共静态void main(字符串[]args)
{
Random dice1=新的Random();
扫描仪输入=新扫描仪(系统输入);
//各种
int die1;
int die2;
字节=1;
字节Yes=1;
字节号=0;
整数合计;
int stop=0;
//我想找个方法把单词改成#s吗
字符串开始=是;
while(stop如果您想从扫描仪中读取int,请尝试使用scanner.nextInt
您可以使用hasNextInt
确定使用nextInt
是否有效:
如果您已经拥有该字符串并希望将其转换为int,请尝试Integer.parseInt
一般来说,如果您想知道是否存在执行基本操作的函数,那么应该检查java.lang、java.util、java.io等中的API(取决于您认为应该在哪里)