題目
計算1+2+3+4+5之和
package ch4;
import java.io.*;
public class ch4_16
{
public static void main(String args[])throws IOException
{
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader buf=new BufferedReader(in);
int a,b,c,d,e,sum;
String stra,strb,strc,strd,stre;
System.out.println("請依序輸入A,B,C,D,E的數值");
stra=buf.readLine();
a=Integer.parseInt(stra);
strb=buf.readLine();
b=Integer.parseInt(strb);
strc=buf.readLine();
c=Integer.parseInt(strc);
strd=buf.readLine();
d=Integer.parseInt(strd);
stre=buf.readLine();
e=Integer.parseInt(stre);
System.out.println("A="+a+",B="+b+",C="+c+",D="+d+",E="+e);
sum=a+b+c+d+e;
System.out.println("A+B+C+D+E="+sum);
}
}
輸出結果
請依序輸入A,B,C,D,E的數值
1
2
3
4
5
A=1,B=2,C=3,D=4,E=5
A+B+C+D+E=15
留言列表