1234567891011121314151617181920212223242526 |
- import java.util.Scanner;
-
- public class Sum{
- public void sumOfNumbers(){
- int result = 1;
- int i = 2;
-
- StringBuilder fact = new StringBuilder("1");
-
- Scanner s = new Scanner(System.in);
- int input = s.nextInt();
-
- if(input != 0){
-
- while(i <= input){
- fact.append(String.format(" + %d", i));
- result += i;
- i++;
- }
-
- System.out.println(String.format("\nHmmm... the answer to that is..\n" + fact.toString() + "\nWhich is " + result + "!", input));
- System.out.println("\nGot anything harder?\n\nIf not, you can enter '0' to close\n----------\n");
- sumOfNumbers();
- }
- }
- }
|