import java.io.*;
public class Applicant
{
int applicantAge;
public boolean checkAge() throws IOException
{
System.out.println(applicantAge);
if (applicantAge>40)
return false;
else
return true;
}
public static void main(String[] args) throws IOException
{
Applicant app=new Applicant();
System.out.println("输入员工年龄:");
app.applicantAge=System.in.read()-48;
app.applicantAge=app.applicantAge*10+System.in.read()-48; if(app.checkAge()==false)
{
System.out.println("拒绝该员工");
}
else
{
System.out.println("接收该员工");
}
}
}
你对ascII码中的 转换不太清楚 read()每回接收一个字符 但是它是ascII表示 不是你想要的真实数据 按照以上程序 就可以了
public class Applicant
{
int applicantAge;
public boolean checkAge() throws IOException
{
System.out.println(applicantAge);
if (applicantAge>40)
return false;
else
return true;
}
public static void main(String[] args) throws IOException
{
Applicant app=new Applicant();
System.out.println("输入员工年龄:");
app.applicantAge=System.in.read()-48;
app.applicantAge=app.applicantAge*10+System.in.read()-48; if(app.checkAge()==false)
{
System.out.println("拒绝该员工");
}
else
{
System.out.println("接收该员工");
}
}
}
你对ascII码中的 转换不太清楚 read()每回接收一个字符 但是它是ascII表示 不是你想要的真实数据 按照以上程序 就可以了
解决方案 »
- java 树怎么弄
- 介绍点java学习的经验吧,对初学者的!
- 求各位给我的计算器跳出一个错误吧
- java中关于ResultSet的方法
- JFreeChart 可以在图表上添加点击事件吗?
- 怎么样才能跟踪程序代码的执行?? 谢谢
- java中 main()是不是 必须要有参数?(初学者提问)
- java的爱好者都进来-Look 一 Look啊!!
- JBuilder高手看过来!!!
- 重入锁ReentrantLock的nonfairTryAcquire方法再次获取同步状态处理逻辑的疑问
- 请各位高手帮忙理解一段代码( 请进)
- 文件名含“ $ ”的文件是临时文件吗?用jad *.class时它不反编译“ $ ”文件?
public class Applicant
{
byte applicantAge;
public boolean checkAge()
{
System.out.println(this.applicantAge);
if (this.applicantAge>40)
return false;
else
return true;
}
public static void main(String[] args) throws IOException
{
Applicant app=new Applicant();
System.out.println("請輸入年齡:");
byte[] x=new byte[5];
System.in.read(x);
//app.applicantAge=(byte)System.in.read();
app.applicantAge=Integer.valueOf(new String(x).trim()).byteValue();
if(!app.checkAge())
{
System.out.println("拒絕該員工");
}
else
{
System.out.println("接收該員工");
}
}
}
--這樣試試
public class Applicant
{
int applicantAge;
public boolean checkAge() throws IOException
{
System.out.println(applicantAge);
if (applicantAge>40)
return false;
else
return true;
}
public static void main(String[] args) throws IOException
{
Applicant app=new Applicant();
System.out.println("输入员工年龄:");
//下面的一句是原文的
//app.applicantAge=(int)System.in.read();
//下面的两句是我添的
app.applicantAge=System.in.read()-48;
app.applicantAge=app.applicantAge*10+System.in.read()-48;
if(app.checkAge()==false)
{
System.out.println("拒绝该员工");
}
else
{
System.out.println("接收该员工");
}
}
}
/**
* get the string input on the screen
*/
public int getInputString(){
try{
this.m_ReadLine=this.m_dis.readInt();
}
catch(IOException e){
System.err.println("Error: Can't get system inputstream!");
}
return this.m_ReadLine;
} DataInputStream m_dis=new DataInputStream(System.in);