Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Forloop {
- public static void main(String[] args) {
- Scanner keyboard=new Scanner(System.in);
- System.out.println("Enter a positive integer under 10:");
- int input=keyboard.nextInt();
- int total=1;
- System.out.print("1");
- for(int i=2;i<=input;i++){
- total=total+i;
- System.out.print(" + "+i);
- }
- System.out.print(" ="+total);
- }
- }
Add Comment
Please, Sign In to add comment