This commit is contained in:
2022-10-13 06:51:41 -05:00
parent 97ebbb64d4
commit eeead47ab0
29 changed files with 1199 additions and 11 deletions

View File

@@ -0,0 +1,37 @@
/*
* 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 lab12_calebfontenot;
/**
*
* @author caleb
*/
public class NestedForPyramid {
public static void main(String[] args) {
int startRight = 0, //Init decending numbers
endSpace = 7; //Init number of whitespaces to pad
// PRIMARY FOR LOOP
for (int row = 1; row <= 128; row += row) {
// Whitespace Moment
for (int startSpace = 0; startSpace < endSpace; startSpace++) {
System.out.print(" ");
}
// Display ascending 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();
endSpace--;
startRight = row;
}
}
}

View File

@@ -10,19 +10,28 @@ package lab12_calebfontenot;
*/
public class NestedWhilePatternC {
public static void main(String[] args)
{
int int1 = 1, int2, int3;
while (int1 <= 6) {
System.out.print(int1 + ": ");
System.out.print("6 5 4 3 2 1");
int2 = 1;
while (int2 != int1) {
System.out.print("\b\b");
int2++;
public static void main(String[] args) {
// Define variables
int numberOfLines = 6;
int rows = 1;
int spacing;
int collums;
//Main while looping
while (rows <= numberOfLines) {
spacing = numberOfLines - rows;
while (spacing >= 1) { //Spacing
System.out.print(" ");
spacing--;
}
collums = rows;
while (collums >= 1) { //Number printing
System.out.print(collums + " ");
collums--;
}
System.out.println();
int1++;
rows++;
}
}
}

View File

@@ -0,0 +1,37 @@
/*
* 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 lab12_calebfontenot;
/**
*
* @author caleb
*/
public class NestedWhilePatternD {
public static void main(String[] args) {
// Define variables
int numberOfLines = 6;
int rows = 1;
int spacing;
int collums;
//Main while looping
while (rows <= numberOfLines) {
spacing = numberOfLines - rows;
while (spacing < 6) { //Spacing
System.out.print(" ");
spacing++;
}
collums = rows;
while (collums <= 6) { // Number printing
System.out.print((collums - rows + 1) + " ");
collums++;
}
System.out.println();
rows++;
}
}
}

View File

@@ -0,0 +1,46 @@
/*
* 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 lab12_calebfontenot;
import java.util.Scanner;
/**
*
* @author caleb
*/
public class Palindrome1 {
public static void main(String[] args) {
// Create a Scanner
Scanner input = new Scanner(System.in);
// Prompt the user to enter a string
System.out.print("Enter a string: ");
String s = input.nextLine();
// The index of the first character in the string
int low = 0;
// The index of the last character in the string
int high = s.length() - 1;
boolean isPalindrome = true;
while (low < high) {
if (s.charAt(low) != s.charAt(high)) {
isPalindrome = false;
break;
}
low++;
high--;
}
if (isPalindrome) {
System.out.println(s + " is a palindrome");
} else {
System.out.println(s + " is not a palindrome");
}
}
}

View File

@@ -0,0 +1,46 @@
/*
* 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 lab12_calebfontenot;
import java.util.Scanner;
/**
*
* @author caleb
*/
public class Palindrome2 {
public static void main(String[] args) {
// Create a Scanner
Scanner input = new Scanner(System.in);
// Prompt the user to enter a string
System.out.print("Enter a string: ");
String s = input.nextLine();
// The index of the first character in the string
int low;
// The index of the last character in the string
int high = s.length() - 1;
boolean isPalindrome = true;
for (low = 0; low < high; low++) {
if (s.charAt(low) != s.charAt(high)) {
isPalindrome = false;
break;
}
//low++;
high--;
}
if (isPalindrome) {
System.out.println(s + " is a palindrome");
} else {
System.out.println(s + " is not a palindrome");
}
}
}

View File

@@ -0,0 +1,28 @@
/*
* 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 lab12_calebfontenot;
/**
*
* @author caleb
*/
public class TestBreak1 {
public static void main(String[] args) {
int sum = 0,
number = 0;
while (number < 20) {
if (sum >= 100) {
break;
}
number++;
sum += number;
System.out.println("Current sum: " + sum);
}
System.out.println("\nThe number is " + number);
System.out.println("The sum is " + sum);
}
}

View File

@@ -0,0 +1,28 @@
/*
* 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 lab12_calebfontenot;
/**
*
* @author caleb
*/
public class TestBreak2 {
public static void main(String[] args) {
int sum = 0,
number; // Define number here intead of inside the for loop so that 'number' doesn't get removed from memory the second the for loop is broken out of.
for (number = 0; number < 20; number++) {
if (sum >= 100) {
break;
}
sum += number;
System.out.println("Current sum: " + sum);
}
System.out.println("\nThe number is " + number);
System.out.println("The sum is " + sum);
}
}

View File

@@ -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 lab12_calebfontenot;
/**
*
* @author caleb
*/
public class TestContinue1 {
public static void main(String[] args) {
int sum = 0,
number = 0;
while (number < 20) {
number++;
sum += number;
if (number == 10 || number == 11) {
continue;
}
}
System.out.println(number);
System.out.println("The sum is " + sum);
}
}

View File

@@ -0,0 +1,25 @@
/*
* 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 lab12_calebfontenot;
/**
*
* @author caleb
*/
public class TestContinue2 {
public static void main(String[] args) {
int sum = 0,
number;
for (number = 0; number < 20; number++) {
sum += number;
if (number == 10 || number == 11) {
continue;
}
}
System.out.println(number);
System.out.println("The sum is " + sum);
}
}