Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class forLoops {
- /*
- 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;
- and finally and increment or decrement operator. ex. i++; the loop starts at the starting point, checks for true, and if true
- 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.
- */
- public static void main(String[] args) {
- for (int i=0; i<6; i++) { // print a row of numbers
- System.out.print(i+ " ");
- }
- for (int i =100; i>0; i--) { // print something 100 times
- System.out.println("hey good lookin");
- }
- for (int i=1; i<101; i++) { // print something 100 times with
- if (i % 5==0) // with 5 per row
- System.out.println("hey good lookin ");
- else
- System.out.print("hey good lookin ");
- }
- long total =0; // add numbers 1 through 100
- for (int i=1; i<=100; i++) {
- total= i+ total;
- }
- System.out.println(total);
- total =1; // factorial
- for (int i=1; i<=20; i++) {
- total = total *i;
- }
- System.out.println(total);
- //make a table
- System.out.printf("INCHES%10s", "FEET"); // print header
- System.out.println("\n ________________"); // print separator
- for (int i =0; i<=144; i+=3){ // print table increments of 3
- System.out.printf(i +"%10.2f",i/12.0);
- System.out.println();
- {
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement