很多关键字写错了
修改了下import java.io.*;
public class Compute
{
public static void main(String[] args)
{
String Str1="";
String Str2="";
try
{
InputStreamReader ins = new InputStreamReader(System.in);
BufferedReader br= new BufferedReader(ins);
Str1=br.readLine();
Str2=br.readLine();
}catch (IOException ie){}
if(Str1.indexOf(".")==-1)
{
int y1=Integer.parseInt(Str1);
int y2=Integer.parseInt(Str2);
int y=y1+y2;
System.out.println("输入的两个数的和为:"+y);
}
else
{
Float f1= Float.parseFloat(Str1);
Float f2= Float.parseFloat(Str2);
Float f= f1+f2;
System.out.println("输入的两个数的和为:"+f);
}
}
}
修改了下import java.io.*;
public class Compute
{
public static void main(String[] args)
{
String Str1="";
String Str2="";
try
{
InputStreamReader ins = new InputStreamReader(System.in);
BufferedReader br= new BufferedReader(ins);
Str1=br.readLine();
Str2=br.readLine();
}catch (IOException ie){}
if(Str1.indexOf(".")==-1)
{
int y1=Integer.parseInt(Str1);
int y2=Integer.parseInt(Str2);
int y=y1+y2;
System.out.println("输入的两个数的和为:"+y);
}
else
{
Float f1= Float.parseFloat(Str1);
Float f2= Float.parseFloat(Str2);
Float f= f1+f2;
System.out.println("输入的两个数的和为:"+f);
}
}
}
/**
*类虽然有点问题,但影响还不大,要是不能运行,要考虑java环境是否正确配置了,避免白忙很久后
*才发现是环境设置的问题
*/
public class Compute {
public static void main(String[] args) {
String str1 = "";//变量的首字母大写
String str2 = "";
try {
InputStreamReader ins = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(ins);
str1 = br.readLine().trim();//这里进行去前后空格处理
str2 = br.readLine().trim();
} catch (IOException ie) {
}
if (str1.indexOf(".") == -1) {
try {
//这里转换也要抓异常,因为不一定转换成功,如"abc"就转不成int
int y1 = Integer.parseInt(str1);
int y2 = Integer.parseInt(str2);
int y = y1 + y2;
System.out.println("输入的两个数的和为:" + y);
} catch (NumberFormatException nfex) {
System.out.println("输入数字格式不对");
}
} else {
try {
//与上面的保持一致,都用基本类型,可以不用封装类型Float
float f1 = Float.parseFloat(str1);
float f2 = Float.parseFloat(str2);
float f = f1 + f2;
System.out.println("输入的两个数的和为:" + f);
} catch (NumberFormatException nfex) {
System.out.println("输入数字格式不对");
}
}
}
}