解析 public class ComputeOddEven { public static void main(String[] args) { int sumOdd=0;//求奇数和的变量 int sumEven=0;//求偶数之和的变量 for(int i=1;i100); } System.out.println("奇数之和为"+sumOdd); System.out.println("偶数之和为"+sumEven); } }...
System.out.println("1-1000 偶数总和:" + evenSum); }}
你好,很高兴回答你的问题。伪代码实现Java程序求1-100之间的奇数和,可以使用以下三种方式:1.for循环实现sum = 0;for(i = 1; i <= 100; i = i + 2){ sum = sum + i;}输出 sum;2.while循环实现sum = 0;i = 1;while(i <= 100){ sum = sum + i; i = i + 2;...
亲亲[开心],很高兴为你解答Java使用伪代码实现一个求1-100之间的奇数和的程序,算法1:直接累加奇数算法描述:直接利用for循环累加1-100的奇数和伪代码实现:sum = 0for i=1 to 100 do if i%2 == 1 then sum = sum + i end ifend forprint sum算法2:利用while循环算法描述:利...
public class Test {public static void main(String[] args){// 打印1~1000所有的奇数new Thread(new Runnable(){public void run(){for(int i=1;i<1000;i+=2){try { Thread.sleep(100); } catch (Exception e) { e.printStackTrace(); }System.out.println("odd:"+i);}}}).start...
Java程序:public class Test17 { public static void main(String[] args) { int n;int sum = 0;for(n=1; n<=2000; n++) { if(n % 2 == 0) { continue;} sum += n;} System.out.println(sum);} } 运行结果:1000000 ...
public class ComputeOddEven { public static void main(String[] args){ int sumOdd=0;//求奇数和的变量 int sumEven=0;//求偶数之和的变量 for(int i=1;i<=100;i++){ while(i%2!=0){ sumOdd+=i;break;} do { if(i%2==0){ sumEven+=i;} break;}while(i>100);} Syste...
import java.io.IOException;public class Test3 {public static void main(String[] args) throws IOException {// 这是使用了continue的例子,但不推荐int sum = 0;for (int i = 0; i < 100; i++) {if (i % 2 == 0) {continue;}sum += i;}System.out.println(sum);// 可以试试三元运算符...
import java.math.*; import java.util.Scanner; public class ceshi1 { public static void main(String[] args) { int anOddNumber = 0; int anEvenNumber = 0; for (int i = 1; i <= 100; i++) { if (i % 2 == 0){ anEvenNumber += i; ...
* */ public class HomeWork24 { public static void main(String[] args) { int sum1=0; int sum2=0; for(int i=1;i<=100;i++){ if(i%2==0){ sum1=sum1+i; }else{ sum2=sum2+i; } } System.out.println("偶数之和为:"+sum1); System.out.println("奇数之和为:"+sum2); } ...