Guest User

Untitled

a guest
Oct 17th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Forloop {
  4.  
  5.  
  6. public static void main(String[] args) {
  7.  
  8. Scanner keyboard=new Scanner(System.in);
  9.  
  10. System.out.println("Enter a positive integer under 10:");
  11. int input=keyboard.nextInt();
  12. int total=1;
  13.  
  14. System.out.print("1");
  15.  
  16. for(int i=2;i<=input;i++){
  17.  
  18. total=total+i;
  19. System.out.print(" + "+i);
  20. }
  21.  
  22. System.out.print(" ="+total);
  23.  
  24. }
  25.  
  26. }
Add Comment
Please, Sign In to add comment