Java 如何在没有.tocharray实例方法的情况下将字符串转换为字符数组
/** 此程序提示用户输入字符串,然后 输出整个字符串的大写字母。 */Java 如何在没有.tocharray实例方法的情况下将字符串转换为字符数组,java,arrays,Java,Arrays,/** 此程序提示用户输入字符串,然后 输出整个字符串的大写字母。 */ 下面是将字符串转换为char[]数组的代码段 public class StringUppercase { public static void main(String [] args) { String input; Scanner keyboard = new Scanner(System.in); System.out.println("Please
下面是将字符串转换为char[]数组的代码段
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;
}
}
字符串输入;
扫描仪键盘=新扫描仪(System.in);
输入=keybaord.nextLine();
char[]nameChar=new char[input.length()];
对于(int i=0;i
以下是将字符串转换为字符数组并以大写形式输出的代码片段
String input;
Scanner keyboard = new Scanner(System.in);
input = keybaord.nextLine();
char[] nameChar = new char[input.length()];
for(int i =0; i < name.length() ; i++)
{
nameChar[i] = name.charAt(i);
}
System.out.println(nameChar);
publicstaticvoidmain(字符串[]args)
{
字符串输入字符串;
System.out.println(“请输入字符串”);
扫描仪sc=新的扫描仪(System.in);
inputString=sc.nextLine();
sc.close();
int len=inputString.length();
char[]name=新字符[len];
对于(int i=0;i
不使用那种方法是愚蠢的。我想您可以在字符串上循环,并为每个字符调用charAt(I)
。@这很愚蠢,但这是一个实验室作业,因此必须根据它进行操作。相关:稍微不那么愚蠢(但相当困难,尤其是当您需要支持非ASCII时)将尝试完全跳过字符串并直接从System.in读取字符。
String input;
Scanner keyboard = new Scanner(System.in);
input = keybaord.nextLine();
char[] nameChar = new char[input.length()];
for(int i =0; i < name.length() ; i++)
{
nameChar[i] = name.charAt(i);
}
System.out.println(nameChar);
public static void main(String[] args)
{
String inputString;
System.out.println("Please Enter the String");
Scanner sc = new Scanner(System.in);
inputString = sc.nextLine();
sc.close();
int len=inputString.length();
char[] name = new char[len];
for(int i =0; i < len; i++)
{
name[i] = inputString.toUpperCase().charAt(i);
}
System.out.println(name);
}