Skip to content

Instantly share code, notes, and snippets.

@ssd863419
Created May 1, 2014 09:56
Show Gist options
  • Save ssd863419/d962c9e21129e5124633 to your computer and use it in GitHub Desktop.
Save ssd863419/d962c9e21129e5124633 to your computer and use it in GitHub Desktop.
A+AA+AAA+AAAA+....
import java.util.Scanner;
public class Test {
public static int numAdd(String inPut, String inPut2){
int result = 0;
if (inPut.equals(inPut2)){
result = Integer.parseInt(inPut);
}else{
int temp = Integer.parseInt(inPut2)/10;
result += Integer.parseInt(inPut2) + numAdd(inPut,String.valueOf(temp));
}
return result;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int inPut ;
do {
System.out.print("input something(0 to quit) :");
inPut = scanner.nextInt();
System.out.println();
String A = Integer.toString(inPut);
String temp = new String();
System.out.println("you enter :" + inPut);
for (int i = 0; i < inPut; i++) {
temp += A;
System.out.print(temp);
if (i < inPut-1) {
System.out.print("+");
}
}
System.out.println(" = " + numAdd(A , temp));
}while ( inPut !=0);
System.out.println("TKS");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment