import java.util.*;
import java.io.*;
public class Cascader {
public static void main(String args[]) throws IOException {
Scanner inputfile = new Scanner(new File("name.txt"));
String name = inputfile.nextLine();
System.out.println("Reading the name...");
for(int i = 0; i < name.length(); i++) {
System.out.println(name.charAt(i));
}
inputfile.close();
}
}
答案 0 :(得分:1)
回答你的问题:你可能没有“保存”新的字符串。 toUpperCase()
方法返回一个新的String,其中每个字符都已更改为大写。
name.toUpperCase(); // does not do anything to the String in the variable 'name'
String newName = name.toUpperCase(); // if name was 'john', newName will be 'JOHN'
name = name.toUpperCase(); // if name was 'john', name will now be 'JOHN'