Given two integers a and B, outputs all integers from A to B and the number's and.
Input format:
The input gives 2 integers a and B in a row, where -100<=a<=b<=100 is separated by a space.
Output format:
The first sequence outputs all integers from A to B, one row per 5 digits, 5 character widths per digit, and right alignment. Finally, output all the numbers in a row.
Input Sample:
-3 8
Sample output:
-3-2-1 0 1
2 3 4) 5 6
7 8
Sum = 30
Import Java.util.Scanner; Public classTest { Public Static void Main(string[] args) {Scannerinch=NewScanner (System.inch);intA, B, I, sum =0, Count =0; A =inch. Nextint (); b =inch. Nextint (); for(i =1; I <= b-a +1; i++) {System. out. printf ("%5d", a+i-1);if(++count%5==0) {//count variable is to eliminate when the integer segment length is a multiple of 5, the more generated a newline, the principle is the use of ++count first after using + +System. out. println (); } }if(Count%5!=0) {System. out. println (); } for(intj = A; J <= B; J + +) {sum + = j; } System. out. Print ("Sum ="); System. out. print (sum); }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Cycle-01. To find integer segments and