?? jisuanqi.java
字號:
import java.io.* ;
public class jisuanqi
{
public static int jia()
{
int c=0;
return 0;
}
public static int jia(int a,int b)
{
int c=a+b;
return c;
}
public static double jia(double a,double b)
{
double c=a+b;
return c;
}
public static void main(String[] args)throws Exception
{
System.out.println("加法計算器,輸入2個加數");
BasicIo.prompt("請輸入a:");
String str1=BasicIo.readString();
int i,flag1=0,flag2=0;
int a=0;
double a1=0;
i=0;
if(str1.charAt(i)=='-')
{
flag2=1;
i++;
}
while(i<str1.length()&&str1.charAt(i)>='0'&&str1.charAt(i)<='9')
{
a=10*a+(str1.charAt(i)-'0');
i++;
if(flag2==1)
{
a=-a;
}
a1=a;
}
if(i<str1.length())
{
if(str1.charAt(i)=='.')
{
flag1=1;
double t=0.1;
i++;
while(i<str1.length())
{
if(str1.charAt(i)>'9'||str1.charAt(i)<'0')
{
System.out.println("輸入a有誤!");
return ;
}
a1=a1+t*(str1.charAt(i)-'0');
t=t/10;
i++;
}
}
else
{
System.out.println("輸入a有誤!");
return ;
}
}
BasicIo.prompt("請輸入b:");
String str2=BasicIo.readString();
flag2=0;
int b=0;
double b1=0;
i=0;
if(str2.charAt(i)=='-')
{
flag2=1;
i++;
}
while(i<str2.length()&&str2.charAt(i)>='0'&&str2.charAt(i)<='9')
{
b=10*b+(str2.charAt(i)-'0');
i++;
if(flag2==1)
{
b=-b;
}
b1=b;
}
if(i<str2.length())
{
if(str2.charAt(i)=='.')
{
i++;
flag1=1;
double t=0.1;
while(i<str2.length())
{
if(str2.charAt(i)>'9'||str2.charAt(i)<'0')
{
System.out.println("輸入b有誤!");
return ;
}
b1=b1+t*(str2.charAt(i)-'0');
t=t/10;
i++;
}
}
else
{
System.out.println("輸入b有誤!");
return ;
}
}
if(str1.length()==0&&str2.length()==0)
{
int c2=jia();
System.out.println("0+0="+c2);
}
else{
if(flag1==0)
{
int c=jia(a,b);
System.out.println(a+"+"+b+"="+c);
}
else {
double c1=jia(a1,b1);
System.out.println(a1+"+"+b1+"="+c1);
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -