⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jisuanqi.java

📁 实现不同类型的数相加。包括整数相加
💻 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 + -