日期:2014-05-17  浏览次数:20869 次

char 该什么用?表示我刚学.虚心请教
import java.util.Scanner;
public class threelianxi {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("请输入你的年龄:");
int old = input.nextInt();
System.out.print("请输入你的性别:");
char nan = input.next();
if (old>=5&&old<=7&& nan == "男"){
System.out.println("你可以搬桌子。");
}
else {
System.out.println("!");
}
}
}

------解决方案--------------------
刚刚没有注意,改成下面的
Java code

package csdn.p36;

import java.util.Scanner;

/**
 * Created by IntelliJ IDEA.
 * User: gaoyong
 * Date: 2011-10-30
 * Time: 17:36:27
 * To change this template use File | Settings | File Templates.
 */
public class Threelianxi {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        System.out.print("请输入你的年龄:");
        int old = input.nextInt();
        System.out.print("请输入你的性别:");
        String nan = input.next();
        if (old>=5&&old<=7&& nan.equals("男")){
            System.out.println("你可以搬桌子。");
        }
        else {
            System.out.println("!");
        }
    }
}