diff --git a/Assignments/lab12_CalebFontenot/ForNested1.html b/Assignments/lab12_CalebFontenot/ForNested1.html new file mode 100644 index 0000000..e254b0b --- /dev/null +++ b/Assignments/lab12_CalebFontenot/ForNested1.html @@ -0,0 +1,48 @@ + + + +ForNested1.java + + + + +
/home/caleb/ASDV-Java/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/ForNested1.java
+
+/*
+ * 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 ForNested1 {
+    public static void main(String[] args)
+    {
+        for (int i = 0; i < 3; ++i)
+        {
+            System.out.print("(i, j) = ");
+            for (int j = 0; j < 4; ++j)
+            {
+                System.out.print("(" + i + ", " + j + ") ");
+            }
+            System.out.println("");
+        }
+    }
+}
+
+
+ diff --git a/Assignments/lab12_CalebFontenot/Lab12_CalebFontenot.html b/Assignments/lab12_CalebFontenot/Lab12_CalebFontenot.html new file mode 100644 index 0000000..b7ba3a6 --- /dev/null +++ b/Assignments/lab12_CalebFontenot/Lab12_CalebFontenot.html @@ -0,0 +1,43 @@ + + + +Lab12_CalebFontenot.java + + + + +
/home/caleb/ASDV-Java/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/Lab12_CalebFontenot.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
+ */
+package lab12_calebfontenot;
+
+/**
+ *
+ * @author caleb
+ */
+public class Lab12_CalebFontenot {
+
+    /**
+     * @param args the command line arguments
+     */
+    public static void main(String[] args)
+    {
+        // TODO code application logic here
+    }
+    
+}
+
+
+ diff --git a/Assignments/lab12_CalebFontenot/NestedForPatternA.html b/Assignments/lab12_CalebFontenot/NestedForPatternA.html new file mode 100644 index 0000000..d4a50ab --- /dev/null +++ b/Assignments/lab12_CalebFontenot/NestedForPatternA.html @@ -0,0 +1,54 @@ + + + +NestedForPatternA.java + + + + +
/home/caleb/ASDV-Java/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/NestedForPatternA.java
+
+/*
+ * 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 NestedForPatternA {
+    public static void main(String[] args)
+    {
+        /*
+        String line = "";
+        //First for loop
+        for (int i = 1; i <= 6; ++i)
+        {
+            line = line + " " + i;
+            System.out.println(line);
+        }
+        */
+        for (int i = 1; i < 7; i++) {
+            for (int j = 1; j < i + 1; j++) {
+                System.out.print(j + " ");
+            }
+                System.out.println();
+        }
+    }
+}
+
+
+ diff --git a/Assignments/lab12_CalebFontenot/NestedForPatternB.html b/Assignments/lab12_CalebFontenot/NestedForPatternB.html new file mode 100644 index 0000000..fbc398f --- /dev/null +++ b/Assignments/lab12_CalebFontenot/NestedForPatternB.html @@ -0,0 +1,54 @@ + + + +NestedForPatternB.java + + + + +
/home/caleb/ASDV-Java/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/NestedForPatternB.java
+
+/*
+ * 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 NestedForPatternB {
+    public static void main(String[] args)
+    {
+        /*
+        String line = "";
+        //First for loop
+        for (int i = 1; i <= 6; ++i)
+        {
+            line = line + " " + i;
+            System.out.println(line);
+        }
+        */
+        for (int i = 6; i > 0; i--) {
+            for (int j = 1; j < i + 1; j++) {
+                System.out.print(j + " ");
+            }
+                System.out.println();
+        }
+    }
+}
+
+
+ diff --git a/Assignments/lab12_CalebFontenot/NestedForPyramid.html b/Assignments/lab12_CalebFontenot/NestedForPyramid.html new file mode 100644 index 0000000..dbf5eca --- /dev/null +++ b/Assignments/lab12_CalebFontenot/NestedForPyramid.html @@ -0,0 +1,64 @@ + + + +NestedForPyramid.java + + + + +
/home/caleb/ASDV-Java/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/NestedForPyramid.java
+
+/*
+ * 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;
+            }
+        
+    }
+}
+
+
+ diff --git a/Assignments/lab12_CalebFontenot/NestedWhilePatternC.html b/Assignments/lab12_CalebFontenot/NestedWhilePatternC.html new file mode 100644 index 0000000..139a72b --- /dev/null +++ b/Assignments/lab12_CalebFontenot/NestedWhilePatternC.html @@ -0,0 +1,64 @@ + + + +NestedWhilePatternC.java + + + + +
/home/caleb/ASDV-Java/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/NestedWhilePatternC.java
+
+/*
+ * 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 NestedWhilePatternC {
+
+    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();
+            rows++;
+            
+        }
+    }
+}
+
+
+ diff --git a/Assignments/lab12_CalebFontenot/NestedWhilePatternD.html b/Assignments/lab12_CalebFontenot/NestedWhilePatternD.html new file mode 100644 index 0000000..f193b84 --- /dev/null +++ b/Assignments/lab12_CalebFontenot/NestedWhilePatternD.html @@ -0,0 +1,64 @@ + + + +NestedWhilePatternD.java + + + + +
/home/caleb/ASDV-Java/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/NestedWhilePatternD.java
+
+/*
+ * 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++;
+            
+        }
+    }
+}
+
+
+ diff --git a/Assignments/lab12_CalebFontenot/Palindrome1.html b/Assignments/lab12_CalebFontenot/Palindrome1.html new file mode 100644 index 0000000..4971327 --- /dev/null +++ b/Assignments/lab12_CalebFontenot/Palindrome1.html @@ -0,0 +1,73 @@ + + + +Palindrome1.java + + + + +
/home/caleb/ASDV-Java/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/Palindrome1.java
+
+/*
+ * 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");
+        }
+    }
+}
+
+
+ diff --git a/Assignments/lab12_CalebFontenot/Palindrome2.html b/Assignments/lab12_CalebFontenot/Palindrome2.html new file mode 100644 index 0000000..24ca9ee --- /dev/null +++ b/Assignments/lab12_CalebFontenot/Palindrome2.html @@ -0,0 +1,73 @@ + + + +Palindrome2.java + + + + +
/home/caleb/ASDV-Java/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/Palindrome2.java
+
+/*
+ * 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");
+        }
+    }
+}
+
+
+ diff --git a/Assignments/lab12_CalebFontenot/TestBreak1.html b/Assignments/lab12_CalebFontenot/TestBreak1.html new file mode 100644 index 0000000..266bd06 --- /dev/null +++ b/Assignments/lab12_CalebFontenot/TestBreak1.html @@ -0,0 +1,55 @@ + + + +TestBreak1.java + + + + +
/home/caleb/ASDV-Java/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/TestBreak1.java
+
+/*
+ * 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);
+    }
+}
+
+
+ diff --git a/Assignments/lab12_CalebFontenot/TestBreak2.html b/Assignments/lab12_CalebFontenot/TestBreak2.html new file mode 100644 index 0000000..5140b36 --- /dev/null +++ b/Assignments/lab12_CalebFontenot/TestBreak2.html @@ -0,0 +1,55 @@ + + + +TestBreak2.java + + + + +
/home/caleb/ASDV-Java/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/TestBreak2.java
+
+/*
+ * 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);
+    }
+}
+
+
+ diff --git a/Assignments/lab12_CalebFontenot/TestContinue1.html b/Assignments/lab12_CalebFontenot/TestContinue1.html new file mode 100644 index 0000000..eb001f4 --- /dev/null +++ b/Assignments/lab12_CalebFontenot/TestContinue1.html @@ -0,0 +1,53 @@ + + + +TestContinue1.java + + + + +
/home/caleb/ASDV-Java/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/TestContinue1.java
+
+/*
+ * 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);
+    }
+}
+
+
+ diff --git a/Assignments/lab12_CalebFontenot/TestContinue2.html b/Assignments/lab12_CalebFontenot/TestContinue2.html new file mode 100644 index 0000000..943d063 --- /dev/null +++ b/Assignments/lab12_CalebFontenot/TestContinue2.html @@ -0,0 +1,52 @@ + + + +TestContinue2.java + + + + +
/home/caleb/ASDV-Java/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/TestContinue2.java
+
+/*
+ * 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);
+    }
+}
+
+
+ diff --git a/Assignments/lab12_CalebFontenot/WhileNested2.html b/Assignments/lab12_CalebFontenot/WhileNested2.html new file mode 100644 index 0000000..aef4036 --- /dev/null +++ b/Assignments/lab12_CalebFontenot/WhileNested2.html @@ -0,0 +1,48 @@ + + + +WhileNested2.java + + + + +
/home/caleb/ASDV-Java/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/WhileNested2.java
+
+/*
+ * 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 WhileNested2 {
+    public static void main(String[] args)
+    {
+        int i = 0;
+        while (i < 3)
+        {
+            System.out.print("(i, j) = ");
+            for (int j = 0; j < 4; ++j)
+                System.out.print("(" + i + ", " + j + ") ");
+            System.out.println("");
+            ++i;
+        }
+    }
+}
+
+
+ diff --git a/Assignments/lab12_CalebFontenot/WhileNested3.html b/Assignments/lab12_CalebFontenot/WhileNested3.html new file mode 100644 index 0000000..ded9ba0 --- /dev/null +++ b/Assignments/lab12_CalebFontenot/WhileNested3.html @@ -0,0 +1,46 @@ + + + +WhileNested3.java + + + + +
/home/caleb/ASDV-Java/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/WhileNested3.java
+
+/*
+ * 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 WhileNested3 {
+    public static void main(String[] args)
+    {
+        for (int i = 0; i < 3; ++i)
+        {
+            System.out.print("(i, j) = ");
+            for (int j = 0; j < 4; ++j)
+                System.out.print("(" + i + ", " + j + ") ");
+            System.out.println("");
+        }
+    }
+}
+
+
+ diff --git a/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/NestedForPyramid.java b/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/NestedForPyramid.java new file mode 100644 index 0000000..a95882c --- /dev/null +++ b/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/NestedForPyramid.java @@ -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; + } + + } +} diff --git a/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/NestedWhilePatternC.java b/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/NestedWhilePatternC.java index 9b420bf..5dfda89 100644 --- a/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/NestedWhilePatternC.java +++ b/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/NestedWhilePatternC.java @@ -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++; + } } } diff --git a/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/NestedWhilePatternD.java b/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/NestedWhilePatternD.java new file mode 100644 index 0000000..292d132 --- /dev/null +++ b/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/NestedWhilePatternD.java @@ -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++; + + } + } +} diff --git a/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/Palindrome1.java b/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/Palindrome1.java new file mode 100644 index 0000000..723c7cb --- /dev/null +++ b/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/Palindrome1.java @@ -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"); + } + } +} diff --git a/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/Palindrome2.java b/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/Palindrome2.java new file mode 100644 index 0000000..e4b41fb --- /dev/null +++ b/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/Palindrome2.java @@ -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"); + } + } +} diff --git a/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/TestBreak1.java b/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/TestBreak1.java new file mode 100644 index 0000000..0f3a190 --- /dev/null +++ b/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/TestBreak1.java @@ -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); + } +} diff --git a/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/TestBreak2.java b/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/TestBreak2.java new file mode 100644 index 0000000..665dc38 --- /dev/null +++ b/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/TestBreak2.java @@ -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); + } +} diff --git a/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/TestContinue1.java b/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/TestContinue1.java new file mode 100644 index 0000000..4966825 --- /dev/null +++ b/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/TestContinue1.java @@ -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); + } +} diff --git a/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/TestContinue2.java b/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/TestContinue2.java new file mode 100644 index 0000000..7e23a7c --- /dev/null +++ b/Assignments/lab12_CalebFontenot/src/lab12_calebfontenot/TestContinue2.java @@ -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); + } +} diff --git a/Test Project/src/main/java/com/mycompany/mavenproject1/Exercise_05_18_C.java b/Test Project/src/main/java/com/mycompany/mavenproject1/Exercise_05_18_C.java new file mode 100644 index 0000000..92fa536 --- /dev/null +++ b/Test Project/src/main/java/com/mycompany/mavenproject1/Exercise_05_18_C.java @@ -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(); + } + } +} \ No newline at end of file diff --git a/Test Project/src/main/java/com/mycompany/mavenproject1/Exercise_05_19.java b/Test Project/src/main/java/com/mycompany/mavenproject1/Exercise_05_19.java new file mode 100644 index 0000000..67c0b94 --- /dev/null +++ b/Test Project/src/main/java/com/mycompany/mavenproject1/Exercise_05_19.java @@ -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 + } + } +} diff --git a/Test Project/target/classes/com/mycompany/mavenproject1/Exercise_05_18_C.class b/Test Project/target/classes/com/mycompany/mavenproject1/Exercise_05_18_C.class new file mode 100644 index 0000000..2aa9d96 Binary files /dev/null and b/Test Project/target/classes/com/mycompany/mavenproject1/Exercise_05_18_C.class differ diff --git a/Test Project/target/classes/com/mycompany/mavenproject1/Exercise_05_19.class b/Test Project/target/classes/com/mycompany/mavenproject1/Exercise_05_19.class new file mode 100644 index 0000000..1e142a6 Binary files /dev/null and b/Test Project/target/classes/com/mycompany/mavenproject1/Exercise_05_19.class differ diff --git a/ZIPs/lab12_CalebFontenot.zip b/ZIPs/lab12_CalebFontenot.zip new file mode 100644 index 0000000..61ba972 Binary files /dev/null and b/ZIPs/lab12_CalebFontenot.zip differ