Enter any two integer numbers and calculate the sum of the numbers divisible by 3 between these two numbers

import java.util.*;
//Enter any two integer numbers and calculate the sum of the numbers divisible by 3 between these two numbers
class chu3 {
    public static void main(String[] args) {
            System.out.println( "Please enter any two integer numbers");
        Scanner in=new Scanner(System.in);
        int a=in.nextInt();
        int b=in.nextInt();
        //Compare the size of a and b, which is a loop Body preparation
        if (a<b){
            a=ba;
            b=ba;
            a=b+a;
        }else{
        }
        //Sum
        int sum = 0;
        for (int i = b; i <=a; i++ ) {
            if (i%3==0) {
                sum+=i;
            }
        }
        System.out.println(The sum of the numbers divisible by 3 from a+" to "+b+" is: "+sum);    
    }
}

Guess you like

Origin blog.csdn.net/dbc_zt/article/details/68952921
Recommended