Advertisement
therrontelford

forLoops

Nov 28th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.48 KB | None | 0 0
  1. public class forLoops {
  2.  
  3. /*
  4. The for loops starts with a starting point ex.  int i=0;   then has a conditional to check for true or false ex.  i<=9;
  5. and finally and increment or decrement operator.  ex.  i++;  the loop starts at the starting point, checks for true, and if true
  6. executes code inside the braces, then goes back to top and increments or decrements, checks for true again, etc. etc until it evaluates to false in which case it will exit the loop.
  7. */
  8.  
  9.     public static void main(String[] args) {
  10.  
  11.        
  12.         for (int i=0; i<6; i++) {    // print a row of numbers
  13.             System.out.print(i+ " ");
  14.         }
  15.         for (int i =100; i>0; i--) {  // print something 100 times
  16.             System.out.println("hey good lookin");
  17.         }
  18.         for (int i=1; i<101; i++) {  // print something 100 times with
  19.             if (i % 5==0)            // with 5 per row
  20.                 System.out.println("hey good lookin ");
  21.             else
  22.                 System.out.print("hey good lookin ");
  23.            
  24.        
  25.            
  26.         }
  27.         long total =0;  // add numbers 1 through 100
  28.         for (int i=1; i<=100; i++) {
  29.              total= i+ total;
  30.              
  31.              
  32.         }
  33.         System.out.println(total);
  34.    
  35.     total =1;           // factorial
  36.     for (int i=1; i<=20; i++) {
  37.         total =  total *i;
  38.     }
  39.     System.out.println(total);
  40.    
  41.     //make a table
  42.     System.out.printf("INCHES%10s", "FEET");   // print header
  43.         System.out.println("\n ________________");  // print separator
  44.         for (int i =0; i<=144; i+=3){       // print table increments of 3
  45.             System.out.printf(i +"%10.2f",i/12.0);
  46.             System.out.println();
  47.             {
  48.         }
  49.            
  50.         }
  51.    
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement