Created
March 28, 2023 14:25
-
-
Save HamsterofDeath/a2431345c0d9e00ef345b8419b1511a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package superprof; | |
public class ReadCode { | |
public static int findSmallest1(int a, int b, int c, int d, int e, int f) { | |
int smallest = a; | |
if (b < smallest) { | |
smallest = b; | |
} | |
if (c < smallest) { | |
smallest = c; | |
} | |
if (d < smallest) { | |
smallest = d; | |
} | |
if (e < smallest) { | |
smallest = e; | |
} | |
if (f < smallest) { | |
smallest = f; | |
} | |
return smallest; | |
} | |
public static int findSmallest2(int a, int b, int c, int d, int e, int f) { | |
if (a <= b && a <= c && a <= d && a <= e && a <= f) { | |
return a; | |
} else if (b <= a && b <= c && b <= d && b <= e && b <= f) { | |
return b; | |
} else if (c <= a && c <= b && c <= d && c <= e && c <= f) { | |
return c; | |
} else if (d <= a && d <= b && d <= c && d <= e && d <= f) { | |
return d; | |
} else if (e <= a && e <= b && e <= c && e <= d && e <= f) { | |
return e; | |
} else { | |
return f; | |
} | |
} | |
public static boolean isTriangleValid1(double side1, double side2, double side3) { | |
if (side1 <= 0 || side2 <= 0 || side3 <= 0) { | |
// All sides must be greater than 0 | |
return false; | |
} else if (side1 + side2 <= side3 || side1 + side3 <= side2 || side2 + side3 <= side1) { | |
// The sum of the lengths of any two sides must be greater than the length of the third side | |
return false; | |
} else { | |
return true; | |
} | |
} | |
public static boolean isTriangleValid2(double side1, double side2, double side3) { | |
boolean isSide1Positive = side1 > 0; | |
boolean isSide2Positive = side2 > 0; | |
boolean isSide3Positive = side3 > 0; | |
boolean isSum12GreaterThan3 = side1 + side2 > side3; | |
boolean isSum13GreaterThan2 = side1 + side3 > side2; | |
boolean isSum23GreaterThan1 = side2 + side3 > side1; | |
boolean isValid = isSide1Positive && isSide2Positive && isSide3Positive && | |
isSum12GreaterThan3 && isSum13GreaterThan2 && isSum23GreaterThan1; | |
return isValid; | |
} | |
public static boolean isTriangleValid3(double side1, double side2, double side3) { | |
return side1 > 0 && side2 > 0 && side3 > 0 && | |
side1 + side2 > side3 && side1 + side3 > side2 && side2 + side3 > side1; | |
} | |
public void calculateSomething(boolean isFlagSet, int x, int y) { | |
if (isFlagSet) { | |
if (x < 0) { | |
if (y < 0) { | |
System.out.println("Result is 1"); | |
} else if (y == 0) { | |
System.out.println("Result is 2"); | |
} else { | |
System.out.println("Result is 3"); | |
} | |
} else if (x == 0) { | |
if (y < 0) { | |
System.out.println("Result is 4"); | |
} else if (y == 0) { | |
System.out.println("Result is 5"); | |
} else { | |
System.out.println("Result is 6"); | |
} | |
} else { | |
if (y < 0) { | |
System.out.println("Result is 7"); | |
} else if (y == 0) { | |
System.out.println("Result is 8"); | |
} else { | |
System.out.println("Result is 9"); | |
} | |
} | |
} else { | |
if (x < 0) { | |
if (y < 0) { | |
System.out.println("Result is 10"); | |
} else if (y == 0) { | |
System.out.println("Result is 11"); | |
} else { | |
System.out.println("Result is 12"); | |
} | |
} else if (x == 0) { | |
if (y < 0) { | |
System.out.println("Result is 13"); | |
} else if (y == 0) { | |
System.out.println("Result is 14"); | |
} else { | |
System.out.println("Result is 15"); | |
} | |
} else { | |
if (y < 0) { | |
System.out.println("Result is 16"); | |
} else if (y == 0) { | |
System.out.println("Result is 17"); | |
} else { | |
System.out.println("Result is 18"); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment