Home>

I am a java beginner.
I want to perform string conversion using the methods of the String class, but the following error appears when compiling.
How should you deal with it?
Please answer.

Convert2.java;11: Error: Missing'.class'
String s = line.substring(int 4);
* It is displayed as ^ below 4.

Applicable source code

import java.io.*;
public class Henkan{
public static void main(String[] args){
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try {
String line;
while ((line = reader.readLine()) != null) {
String s = line.replace('_','?');
String s = line.toLowerCase();
String s = line.substring(int 4);
System.out.println(s);
}
} catch (IOException e) {
System.out.println(e);
}
}
}

  • Answer # 1

    I tried to move it for the time being.

    import java.io.*;
    public class Henkan {
        public static void main(String[] args){
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            try {
                String line;
                while ((line = reader.readLine()) != null) {
                    String s = line.replace('_','?');
                    // You don't need the first String because String s is already defined
                    // In the line above, I replaced the input string but didn't use the result
                    // String s = line.toLowerCase();
                    s = s.toLowerCase();
                    // String s = line.substring(int 4);
                    // String is not needed and int before 4 is not needed.
                    s = s.substring(4);
                    System.out.println(s);
                }
            } catch (IOException e) {
                System.out.println(e);
            }
        }
    }

  • Answer # 2

    intIs unnecessary. ArgumentFourJust please