我对 Java 很陌生,编译时出现以下两个错误:
stringConvert3.java:29: illegal start of expression
public static void main (String [] args) throws Exception //Main
^
stringConvert3.java:57: ';' expected
private class InnerToLowerCaseString //Second class (Inner) to convert to lower case
^
以下是我正在工作的代码。. .
import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
//java.lang.needed to perform the "squeeze" method on strings.
public class stringConvert3 //First class and actual program.
{
static Scanner console = new Scanner (System.in);
public void printEven (){
String str;
public static void main (String [] args) throws Exception //Main
{
String str;
//The following imports the 5 line test text from a saved file (test.txt).
Scanner inFile = new Scanner (new FileReader("c:\\test.txt"));
while (inFile.hasNextLine()){
String line = inFile.nextLine();
System.out.printf("Scan = %s\n", line);
String save;
save = line;
str = save;
System.out.printf ("Receive: <%s>\n", str);
InnerToLowerCaseString innerString = this.new InnerToLowerCaseString ();
str = InnerToLowerCaseString.lowerCase (str);
str = save;
str = trimmed (str); //Trims and abreviates.
System.out.printf ("Trimmed: <%s>\n", str);
str = squeeze (str); //Squeezes text.
System.out.printf ("Squeezed: <%s>\n", str);
if (str.length () >= 50)
str = str.substring (0,20);
}
private class InnerToLowerCaseString //Second class (Inner) to convert to lower case
{ //Brace to start the second class.
//Following method converts all letters of String to lower case letters.
private String lowerCase (String str)
{
str = str.toLowerCase();
System.out.printf ("Convert to Lower: <%s>\n", str);
return str;
}
} //Brace to end the second class.
}
public class threeMethods //Third class, containing three methods.
{
public static String trimmed (String str) //First method.
{
Scanner inFile = new Scanner (new FileReader ("c:\\test.txt"));
return str.trim ();
}
public static String trimmed (String str, int len) //Second method.
{
str = trimmed (str);
if (str.length () > 10)
return str.substring (0, 10);
else
return str;
}
public static String squeeze (String str) //Third method.
{
int length;
do
{
length = str.length ();
str = str.replaceAll (" ", " ");
} while (length != str.length ());
return (str);
} //End of squeeze section.
} // End of the main.
}//End of stringConvert3 program.