lab12
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.mycompany.mavenproject1;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class Exercise_05_18_C {
|
||||
public static void main(String[] args) {
|
||||
// Display pattern C
|
||||
int numberOfLines = 6;
|
||||
System.out.println("Pattern C");
|
||||
for (int rows = 1; rows <= numberOfLines; rows++) {
|
||||
for (int s = numberOfLines - rows; s >= 1; s--) {
|
||||
System.out.print(" ");
|
||||
}
|
||||
for (int col = rows; col >= 1; col--) {
|
||||
System.out.print(col + " ");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.mycompany.mavenproject1;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class Exercise_05_19 {
|
||||
public static void main(String[] args) {
|
||||
int startRight = 0, // Initialize decending numbers
|
||||
endSpace = 7; // Initialize number of white space in row
|
||||
// Display number of rows and numbers in each row
|
||||
for (int row = 1; row <= 128; row += row) {
|
||||
// Display white space
|
||||
for (int startSpace = 0; startSpace < endSpace; startSpace++) {
|
||||
System.out.print(" ");
|
||||
}
|
||||
// Display acending numbers
|
||||
for (int l = 1; l <= row; l += l) {
|
||||
System.out.printf("%4d", (l));
|
||||
}
|
||||
// Display decending numbers
|
||||
for (int r = startRight; r > 0 ; r /= 2 ) {
|
||||
System.out.printf("%4d", (r));
|
||||
}
|
||||
System.out.println(); // End line
|
||||
endSpace--; // Decrement endSpace
|
||||
startRight = row; // Assign row to startRight
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user