Merge branch 'Compile-Code' of https://github.com/Patel-Mann/CPSC-499 into Compile-Code

This commit is contained in:
Mann Patel
2025-10-28 22:22:07 -06:00
4 changed files with 59 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
public class Test {
public class Test_0 {
public int methodForLoop() {
int val = 1;

View File

@@ -0,0 +1,28 @@
public class test_1{
public int calculate(int x){
switch(x){
case 1: x += 10;
break;
case 2: x *= 2:
break;
default: x = -1;
}
try{
x = riskyOp(x);
} catch (Exception e){
x = 0;
}
return finalValue(x);
}
private int riskyOp(int input) Exception {
if (input < 0){
throw new Exception("Negative input");
}
return input + 5;
}
private int finalValue(int val){
return val*2;
}
int result = this.calculate(2);
}

View File

@@ -0,0 +1,12 @@
public class Test_2{
public int factorial(int n){
if(n < 0){
reutrn -1;
}
if (n == 0|| n==1){
return 1;
}
return n * factorial(n-1);
}
int result = this.factorial(5);
}

View File

@@ -0,0 +1,17 @@
public class Test_3{
public int search(int [][] matrix, int to_search){
for(int i = 0; i < matrix.lenght; i++){
for(int j = 0; j < matrix[i].legth; j++) {
if (matrix[i][j] == to_search){
return true;
}
}
}
return false;
boolean result = this.contains(new int[][] {
{1,2,3},
{22,42,45},
{38,26,16}}, 42);
}