Advertisement
Felanpro

uppgift85

Nov 19th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package skola;
  7. import java.util.Scanner;
  8. /**
  9. *
  10. * @author Felix 1
  11. */
  12. public class Uppgift85 {
  13.  
  14. /**
  15. * @param args the command line arguments
  16. */
  17. public static void main(String[] args) {
  18. Scanner inmatning = new Scanner(System.in);
  19. System.out.print("n: ");
  20. int n = inmatning.nextInt();
  21. int summa = 0;
  22. for(int i = 1; i <= n; i++)
  23. {
  24. summa += i;
  25. if(i == n)
  26. System.out.print(i + " = " + summa);
  27. else
  28. System.out.print(i + " + ");
  29. }
  30. }
  31.  
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement