Find the odd sum of any two number ranges

The code is as follows:

/*Find odd numbers such as any two number ranges and * / import Java util. Scanner; Class demo19 {public static void main (string [] args) {scanner SC = new scanner (system. In); system. Out. Println ("please enter two integers:"); int m = sc.nextint(); int n = sc.nextint(); / / traverse all numbers in the range of two numbers. If it is an odd number, add int sum = 0; if (M > n) {int t = m; m = n; n = t;} for(int i=m;i<=n;i++){ if(i%2!=0) sum+=i; } System. out. Println (odd sum within the range of M + "and" + N + ": + sum);}}

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>