【发布时间】:2015-04-23 03:00:41
【问题描述】:
// I have to prompt the user to input the String and store into Char [] array
// I know that we can use .toCharArray instance method to store the string
// into Character array.
// But I do not have to use that method, so I reference the string input to
// char array but I got an compiler error saying cannot convert string to char
// This is I have done So far
import java.util.Scanner;
/** 这个程序提示用户输入一个字符串,然后 输出整个字符串大写字母。 */
public class StringUppercase
{
public static void main(String [] args)
{
String input;
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter a String " );
input = keyboard.nextLine();
char[] name;
}
}
【问题讨论】:
-
不使用这种方法很愚蠢。我想你可以遍历字符串并为每个字符调用
charAt(i)。 -
@Thilo 这很傻,但这是一个实验室任务,所以必须按照它来。
-
稍微不那么傻(但相当困难,特别是如果您需要支持非ASCII)将尝试完全跳过String并直接从System.in读取字符。 stackoverflow.com/questions/1066318/…