在Java声明中使用什么变量
在提示用户使用scanner类插入符号时,最好使用什么变量
import java.util.Scanner;
public class characterSquare
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print( "Please enter a symbol");
'x' = sc.nextLine();
System.out.print( 'x', 'x', 'x' ,'x', 'x');
}
}
# 1 楼答案
根据documentation,
Scanner.nextLine()
返回一个String
。因此,必须将变量声明为字符串