1. 求1-100的和
public class mm {
public static void main(String[] args) {
int sum = 0;
int i = 1;
while (i<=100){
sum +=i;
i++;
}
System.out.println("求1-100的和为:"+sum);
}
}
2. 求1-100的奇数的和
public class mm {
public static void main(String[] args) {
int sum = 0;
int i = 1;
while (i<=100){
sum=sum+i;
i+=2;
}
System.out.println("求1-100的奇数和为:"+sum);
}
}
3. 求1-100的偶数的和
public class mm {
public static void main(String[] args) {
int sum = 0;
int i = 1;
while (i<=100){
i++;
if(i%2==0){
sum=sum+i;
}
}
System.out.println("求1-100的偶数和为:"+sum);
}
}
4.求1-100中10的倍数的数值
public class nn {
public static void main(String[] args) {
int sum = 0;
int i = 1;
while (i<=100){
i++;
if(i%10==0){
sum=sum+i;
System.out.println("求1-100的中10的倍数的数值为:"+i);
}
}
}
}
5.求1-100中奇数的和与偶数的和的差
public class nn {
public static void main(String[] args) {
int sum = 0;
int i = 1;
int o = 0;
while (i<=100){
i++;
if(i%2==0){
sum=sum+i;
}else {
o=o+i;
}
}
System.out.println("求1-100中奇数的和与偶数的和的差为:"+(o-sum));
}
}
6.求1-100中5的倍数的数值的个数
public class nn {
public static void main(String[] args) {
int i = 1;
int c = 0;
int sum=0;
while (i<=100){
i++;
if(i%5==0){
sum=sum+i;
c++;
System.out.println("1-100中5的倍数的数值为:"+i);
}
}
System.out.println("1-100中5的倍数的个数为:"+c);
}
}
7.求1-100中偶数的个数
public class nn {
public static void main(String[] args) {
int c=0;
int i = 1;
while (i<=100){
i++;
if(i%2==0){
System.out.println("求1-100的偶数为:"+i);
c++;
}
}
System.out.println("求1-100的偶数个数为:"+c);
}
}
8.求1-100中能被5和4整除的数值
public class nn {
public static void main(String[] args) {
int i = 1;
while (i<=100){
i++;
if(i%5==0&&i%4==0){
System.out.println("求1-100中能被5和4整除的数值为:"+i);
}
}
}
}
9.求1-100中的奇数,并能被3整除的数
public class nn {
public static void main(String[] args) {
int i = 1;
while (i<=100){
i++;
if(i%3==0&&i%2!=0){
System.out.println("求1-100中的奇数,并能被3:"+i)
}
}
10.求1-10中的偶数,并能被8整除的偶数的个数
public class nn {
public static void main(String[] args) {
int c=0;
int i = 1;
while (i<=100){
i++;
if(i%2==0&&i%8==0){
c++;
}
}
System.out.println("求1-100的偶数个数为:"+c);
}
}