这样写也可以
public class test{ public static void main(String[] args){ int sum=0; int num=2; while(num<=50){ if(num%2==0){ sum+=num; } num++; } System.out.println("50以内的偶数之和为:"+sum); } }
public class test{ public static void main(String[] args){ int sum=0; int num=2; while(num<=50){ if(num%2==0){ sum+=num; } num++; } System.out.println("50以内的偶数之和为:"+sum); } }
2024-05-10
举报