Sum.java 755B

1234567891011121314151617181920212223242526
  1. import java.util.Scanner;
  2. public class Sum{
  3. public void sumOfNumbers(){
  4. int result = 1;
  5. int i = 2;
  6. StringBuilder fact = new StringBuilder("1");
  7. Scanner s = new Scanner(System.in);
  8. int input = s.nextInt();
  9. if(input != 0){
  10. while(i <= input){
  11. fact.append(String.format(" + %d", i));
  12. result += i;
  13. i++;
  14. }
  15. System.out.println(String.format("\nHmmm... the answer to that is..\n" + fact.toString() + "\nWhich is " + result + "!", input));
  16. System.out.println("\nGot anything harder?\n\nIf not, you can enter '0' to close\n----------\n");
  17. sumOfNumbers();
  18. }
  19. }
  20. }