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表示 不是你想要的真实数据 按照以上程序 就可以了
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);