8 digital inputs sum [8] program
Title: seeking s = a + aa + aaa + aaaa + aa ... the value of a, where a is a number. E.g. 2 + 22 + 222 + 2222 + 22222 (in this case the sum total of the number 5), a control keyboard a few numbers together.
Program Analysis: The key is to calculate the value of each item.
package cskaoyan; public class cskaoyan8 { @org.junit.Test public void sum() { java.util.Scanner in = new java.util.Scanner(System.in); int number = in.nextInt(); int count = in.nextInt(); int s = 0; int ss = 0; for (int i = 0; i < count; i++) { s += number; ss += s; number = number * 10; System.out.println("每一项的值:" + s); } System.out.println("总和:" + ss); in.close(); } }