do…while
/* do while 一百以为偶数的和
奈何桥
2021/3/20
*/
public class sc3 {
public static void main(String[] args) {
int n = 0,i = 2;
do
{n=n+i;i+=2;}while (i <= 100);
System.out.println(n);
}
}
while
/* 用while一百以内偶数的和
奈何桥
2021/3/20
*/
public class sc2 {
public static void main(String[] args) {
int n = 0, i = 2;
while (i <= 100)
{n=n+i;i+=2;}
System.out.println( n );
}
}
for
/* 用for100以内的偶数相加
2021/3/20
奈何桥
*/
public class scsc {
public static void main(String[] args) {
int n = 0;
for (int i = 0; i <= 100; i++) {
if (i %2 != 0)
continue;
n = n +i;
}
System.out.println(n );
}
}