-3
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();
    }
}
4

1 回答 1

1

回答您的问题:您可能没有“保存”新字符串。该toUpperCase()方法返回一个新字符串,其中每个字符都已更改为大写。

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'
于 2013-09-23T19:45:39.613 回答