偶是初学者,写一程序,其实要实现的东西很简单,要求输入三个一位整数a,b,c,程序验证c是不是a、b的差,但是下边的程序怎么也实现不了,跟一本书上的是一样的?怎么回事?请高手指点import java.io.*;public class ConsoleDemo
{
public static void main(String[] args)
{
System.out.println("Please type an integer(a digit):");
int r = -1;
int a = 0,b = 0,c = 0;
try
{
a = System.in.read();
}
catch(IOException e)
{
System.err.println("Exception!");
} try
{
r = System.in.read();
}
catch(IOException e)
{
System.err.println("Exception!");
}
if(r==13)
System.out.println("Please type another integer(a digit):"); try
{
b = System.in.read();
}
catch(IOException e)
{
System.err.println("Exception!");
} try
{
r = System.in.read();
}
catch(IOException e)
{
System.err.println("Exception!");
}
if(r==13)
System.out.println("The substraction of the two integers is(a digit):"); try
{
c = System.in.read();
}
catch(IOException e)
{
System.err.println("Exception!");
} try
{
r = System.in.read();
}
catch(IOException e)
{
System.err.println("Exception!");
}
if(r==13)
{
int i = a-b;
c = c-48;
if(c==i)
System.out.println("Very good");
else
System.out.println("Sorry ,Try again!");
} try
{
r = System.in.read();
}
catch(IOException e)
{
System.err.println("Exception!");
}
}
}
{
public static void main(String[] args)
{
System.out.println("Please type an integer(a digit):");
int r = -1;
int a = 0,b = 0,c = 0;
try
{
a = System.in.read();
}
catch(IOException e)
{
System.err.println("Exception!");
} try
{
r = System.in.read();
}
catch(IOException e)
{
System.err.println("Exception!");
}
if(r==13)
System.out.println("Please type another integer(a digit):"); try
{
b = System.in.read();
}
catch(IOException e)
{
System.err.println("Exception!");
} try
{
r = System.in.read();
}
catch(IOException e)
{
System.err.println("Exception!");
}
if(r==13)
System.out.println("The substraction of the two integers is(a digit):"); try
{
c = System.in.read();
}
catch(IOException e)
{
System.err.println("Exception!");
} try
{
r = System.in.read();
}
catch(IOException e)
{
System.err.println("Exception!");
}
if(r==13)
{
int i = a-b;
c = c-48;
if(c==i)
System.out.println("Very good");
else
System.out.println("Sorry ,Try again!");
} try
{
r = System.in.read();
}
catch(IOException e)
{
System.err.println("Exception!");
}
}
}
解决方案 »
- 真心求教java怎么播放url地址的MP3.
- 这种写法能获取当前时间吗?
- 一个算法问题
- JAVA_OPTS的设置
- 求救,UndeclaredThrowableException异常,请教如何解决??
- 在pl/sql developer里,用什么sql去执行一个存储过程?
- 今天去书店看了一下,没有《核心技术,卷I,》第五版了,只有第六版,问问各位,第六版值不值的买?
- 命令行里执行java、javac时怎样才都不需要指定路径,求助!
- 有一个java.sql.Time xTime,getHour()方法要如何写才能通用并且正确得到 xTime 里面的小时值?
- 为什么少取一个元素?-棘手!
- JAVA初级问题
- 覆盖问题
{
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
String sA = null;
String sB = null;
String sC = null;
try
{
sA = br.readLine();
sB = br.readLine();
sC = br.readLine();
}
catch(IOException ex)
{
ex.printStackTrace();
}
if (Integer.parseInt(sA)- Integer.parseInt(sB) == Integer.parseInt(sC))
{
System.out.println("TRUE");
}
else
{
System.out.println("False"+String.valueOf(Integer.parseInt(sA)- Integer.parseInt(sB)));
}
}
}
public static void main(String[] args) {
System.out.println("Please type an integer(a digit):");
int r = -1,m=-1;
int a = 0, b = 0, c = 0; try {
a = System.in.read();
} catch (IOException e) {
System.err.println("Exception!");
} try {
r = System.in.read();
System.in.read();
} catch (IOException e) {
System.err.println("Exception!");
}
if (r == 13)
System.out.println("Please type another integer(a digit):"); try {
b = System.in.read();
} catch (IOException e) {
System.err.println("Exception!");
} try {
m = System.in.read();
System.in.read();
} catch (IOException e) {
System.err.println("Exception!");
}
if (m == 13)
System.out.println("The substraction of the two integers is(a digit):"); try {
c = System.in.read();
} catch (IOException e) {
System.err.println("Exception!");
} try {
r = System.in.read();
System.in.read();
} catch (IOException e) {
System.err.println("Exception!");
}
if (r == 13) {
int i = a - b;
c = c - 48;
if (c == i)
System.out.println("Very good");
else
System.out.println("Sorry ,Try again!");
} try {
r = System.in.read();
} catch (IOException e) {
System.err.println("Exception!");
}
}
}
将读入的字节流转换成字符流。