0

I need to create a Java program named UpperOrLower that asks a user to type a number and prints "Uppercase or lowercase: true" if the unicode character with that number is either uppercase or lowercase and "Uppercase or lowercase: false" otherwise.

import java.util.Scanner;

public class UpperOrLower {
        public static void main(String args[]) {

                Scanner input = new Scanner(System.in);

                System.out.print("Enter an integer: ");
                int value = input.nextInt();
                char digit = (char) value;
                boolean isUpperOrLower =
                        (Character.isUpperCase || Character.isLowerCase);

                System.out.println("Uppercase or Lowercase: " +isUpperOrLower);

        }
}

Here's what I have, I keep getting errors, and I have no idea how to fix them.

4

3 回答 3

3

Character.isUpperCase(char c)接受一个角色。您需要调用传入角色的方法,以便它知道它正在测试什么。

boolean isUpperOrLower =
                    (Character.isUpperCase(digit) || Character.isLowerCase(digit));
于 2012-09-18T00:27:08.490 回答
3

试试这个:

boolean isUpperOrLower = Character.isUpperCase(digit) || Character.isLowerCase(digit);

isUpperCase并且是以s 作为参数的类isLowerCase的静态方法。Characterchar

你也可以这样做:

boolean isUpperOrLower = (digit >= 'A' && digit <= 'z')
于 2012-09-18T00:26:00.233 回答
3
import java.util.Scanner;

public class UpperOrLower { public static void main(String args[]) {

            Scanner input = new Scanner(System.in);

            System.out.print("Enter an integer: ");
            int value = input.nextInt();
            char digit = (char) value;
            boolean isUpperOrLower =
                    (Character.isUpperCase (digit) || Character.isLowerCase(digit));
            System.out.println("The Charecter is: " +digit);
            System.out.println("Uppercase or Lowercase: " +isUpperOrLower);

    }
}
于 2012-09-18T00:32:04.133 回答