Advertisement
thotfrnk

forloops1.java

Nov 11th, 2022 (edited)
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.41 KB | None | 0 0
  1. public class number1 {
  2.     public static void main(String[] args) {
  3.  
  4.         //Construct a FOR loop that will print the first 100 positive integers and the sum of these integers.
  5.  
  6.         int sum=0;
  7.  
  8.         for (int i=0; i<=100; i++) {
  9.             System.out.printf("%d\n", i);
  10.  
  11.             sum += i;
  12.         }
  13.         System.out.println("The sum of the first 100 positive integers are: " +sum);
  14.  
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement