简体   繁体   English

表达式的非法开始 - Java

[英]illegal start of expression- Java

why do I get: illegal start of expression -public static int noOfLetters(String str){ error?为什么我会得到:非法开始表达式 -public static int noOfLetters(String str){ 错误? and how could I fix it?我该如何解决?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM