[英]illegal start of expression- Java
為什么我會得到:非法開始表達式 -public static int noOfLetters(String str){ 錯誤? 我該如何解決?
public class Mmn15 {
public static int digInNumFor(int num, int dig) {
Scanner scan = new Scanner(System.in);
num = scan.nextInt();
dig = scan.nextInt();
int counter = 0;
for (counter = 0; num > dig;) {
if (num % 10 == dig); {
/** reduce num*/
num = num / 10;
counter++;
return counter;
}
// This part is where I get the error:
public static int noOfLetters(String str){
Scanner scan = new Scanner(System.in);
str = scan.nextLine();
String letter = 0;
int[] count = new int[letter];
/** Count array with frequency of characters
*/
int i;
for (i = 0; i < str.length(); i++)
if (str.charAt(i) != ' ')
count[(int) str.charAt(i)]++;
int n = i;
/** Prints the characters that are more than 0
*/
for (i = 0; i < n; i++)
if (count[(int) str.charAt(i)] == 1)
System.out.print(str.charAt(i));
}
}
}
}
public class Mmn15 {
public static int digInNumFor(int num, int dig) {
Scanner scan = new Scanner(System.in);
num = scan.nextInt();
dig = scan.nextInt();
int counter = 0;
for (counter = 0; num > dig;) {
if (num % 10 == dig) {
/** reduce num*/
num = num / 10;
counter++;
return counter;
}
// Method Body ends
}
public static int noOfLetters(){
Scanner scan = new Scanner(System.in);
String str = scan.nextLine();
int letter = 26;
int[] count = new int[letter];
/** Count array with frequency of characters
*/
int i;
for (i = 0; i < str.length(); i++)
if (str.charAt(i) != ' ')
count[str.charAt(i) - 'a']++;
int n = i;
/** Prints the characters that are more than 0
*/
for (i = 0; i < 26; i++)
if (count[(int) str.charAt(i)] >= 1)
System.out.print(str.charAt(i));
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.