Skip to content

Instantly share code, notes, and snippets.

@ssd863419
Created May 1, 2014 23:39
Show Gist options
  • Save ssd863419/5f0c348402ef9b7a5005 to your computer and use it in GitHub Desktop.
Save ssd863419/5f0c348402ef9b7a5005 to your computer and use it in GitHub Desktop.
6=1+2+3 ......
import java.util.Scanner;
public class Test {
public static boolean factorSum(int inPut){
int result = 0;
for (int i = 1; i <= inPut/2; i++) {
if (inPut%i == 0) {
result += i;
}
}
if (result == inPut) {
return true;
}else{
return false;
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int inPut ;
do {
System.out.print("input num(0 to quit) :");
inPut = scanner.nextInt();
System.out.println();
for (int i = 1; i < inPut; i++) {
if (factorSum(i)) {
System.out.print(i + ",");
}
}
}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