Created
May 1, 2014 09:56
-
-
Save ssd863419/d962c9e21129e5124633 to your computer and use it in GitHub Desktop.
A+AA+AAA+AAAA+....
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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