日期:2014-05-20 浏览次数:20762 次
System.out.println("请输入性别:");
String inp = new Scanner(System.in).next();
boolean sex = "男".equals(inp);
if (sex) {
System.out.println("先生你好");
} else {
System.out.println("女士你好");
}
package com.han;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
public class CSDN_Forum_1 {
public CSDN_Forum_1() {
// TODO Auto-generated constructor stub
byte[] b = new byte[1024];
try {
System.out.println("请你输入性别: ");
System.in.read(b);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String input;
try {
input = new String(b, "UTF-8");
System.out.println(input);
if (input.equals("男")) {
System.out.println("先生你好");
} else if (input.equals("女")) {
System.out.println("女士你好");
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new CSDN_Forum_1();
}
}
package com.han;
import java.io.IOException;
import java.io.UnsupportedEncodingException;