首页 > 其他分享 >Struct

Struct

时间:2023-10-22 13:03:04浏览次数:31  
标签:Struct 奇数 int 偶数 evensum oddsum

package com.chen.struct;

public class ForDemo02 {
public static void main(String[] args) {
//练习一:计算0到100之间奇数和偶数的和
int oddsum = 0;
int evensum = 0;

for (int i = 0; i < 100; i++) {
if (i%2!=0){//奇数
oddsum += i;
}else {//偶数
evensum += i;
}
}
System.out.println("奇数的和:"+oddsum);
System.out.println("偶数的和:"+evensum);
}
}

 

标签:Struct,奇数,int,偶数,evensum,oddsum
From: https://www.cnblogs.com/jingyichenloveningning/p/17780298.html

相关文章

  • Struct ForDemo01
    packagecom.chen.struct;importjava.util.Scanner;publicclassForDemo01{publicstaticvoidmain(String[]args){inta=1;//初始化条件while(a<100){//条件判断System.out.println(a);//循环体a+=2;//迭代}......
  • Struct ForDemo05
    packagecom.chen.struct;publicclassForDemo05{publicstaticvoidmain(String[]args){int[]numbers={10,20,30,40,50};for(inti=0;i<5;i++){System.out.println(numbers[i]);}System.out.println("=......
  • Struct ForDemo04
    packagecom.chen.struct;publicclassForDemo04{publicstaticvoidmain(String[]args){//打印九九乘法表//1.先打印第一列//2.把固定的1在用一个循环包起来//3.去掉重复项,i=j;//调整样式for(inti=1;i<=9;i......
  • Codeforces Round 865 (Div. 2) B. Grid Reconstruction
    给一个\(2\timesn\)的网格,且\(n\)是偶数。你需要将\(1\sim2\timesn\)填入这个网格。一条路径是从\((1,1)\)开始,每次只能向右或向下,到\((2,n)\)结束时,所经过的位置。按经过点的顺序标号,一两条路径的代价是\(cost=a_1-a_2+a_3-a_4+\cdots=\sum_{i=1......
  • CF1003E Tree Constructing
    很trivial的构造题首先上来判掉一些显然无解的情况,然后考虑既然最后直径长为\(d\)那么不妨先搞一条长度为\(d\)的链来考虑在链上接一些点使得直径不会变长,对于链上的某个点,它最多能接上的链的长度就是它到两个端点距离的最小值不妨设计递归函数求解,设solve(x,dis,lim)表示在\(x......
  • Struct IfDemo02
    packagecom.chen.struct;importjava.util.Scanner;publicclassIfDemo02{publicstaticvoidmain(String[]args){//考试分数大于60分就是及格,小于60分就是不及格。Scannerscanner=newScanner(System.in);System.out.println("请输入成......
  • Struct SwitchDemo01
    packagecom.chen.struct;importjava.util.Scanner;publicclassSwitchDemo01{publicstaticvoidmain(String[]args){//case穿透//switch匹配一个具体的值chargrade='C';switch(grade){case'A':......
  • Struct SequenceDemo01
    packagecom.chen.struct;publicclassSequenceDemo01{publicstaticvoidmain(String[]args){System.out.println("hello1");System.out.println("hello2");System.out.println("hello3");System.o......
  • Struct IfDemo03
    packagecom.chen.struct;importjava.util.Scanner;publicclassIfDemo03{publicstaticvoidmain(String[]args){//考试分数大于60分就是及格,小于60分就是不及格。Scannerscanner=newScanner(System.in);System.out.println("请输入成......
  • Struct SwitchDemo02
    packagecom.chen.struct;publicclassSwitchDemo02{publicstaticvoidmain(String[]args){Stringname="种崎敦美";//JDK7的新特性,表达式结果可以是字符串!!!//字符的本质还是数字//反编译Java----class(字节码文件)-----反编译(ID......