用while语句求1~100之和
public class Ex3_5 {
public static void main(String[] args){
int n=1,sum=0;
while(n<=100)
{
sum+=n;
n++;
}
System.out.println("sum="+sum);
}
}
用while语句求1~100之和
public class Ex3_5 {
public static void main(String[] args){
int n=1,sum=0;
while(n<=100)
{
sum+=n;
n++;
}
System.out.println("sum="+sum);
}
}