diff --git a/lab9_CalebFontenot/lab9_CalebFontenot.docx b/lab9_CalebFontenot/lab9_CalebFontenot.docx new file mode 100644 index 0000000..636c1fb Binary files /dev/null and b/lab9_CalebFontenot/lab9_CalebFontenot.docx differ diff --git a/lab9_CalebFontenot/src/main/java/com/calebfontenot/lab9_calebfontenot/MinimumOf3.java b/lab9_CalebFontenot/src/main/java/com/calebfontenot/lab9_calebfontenot/MinimumOf3.java index d561639..aea3cb9 100644 --- a/lab9_CalebFontenot/src/main/java/com/calebfontenot/lab9_calebfontenot/MinimumOf3.java +++ b/lab9_CalebFontenot/src/main/java/com/calebfontenot/lab9_calebfontenot/MinimumOf3.java @@ -17,7 +17,7 @@ public class MinimumOf3 { { Scanner scan = new Scanner(System.in); - System.out.println("Please neter 3 numbers to find the minimum of the 3:"); + System.out.println("Please enter 4 numbers to find the minimum of the 4: "); int x = scan.nextInt(); int y = scan.nextInt(); int z = scan.nextInt(); diff --git a/lab9_CalebFontenot/src/main/java/com/calebfontenot/lab9_calebfontenot/MinimumOf4ConditionalOperator.java b/lab9_CalebFontenot/src/main/java/com/calebfontenot/lab9_calebfontenot/MinimumOf4ConditionalOperator.java new file mode 100644 index 0000000..2ef7a77 --- /dev/null +++ b/lab9_CalebFontenot/src/main/java/com/calebfontenot/lab9_calebfontenot/MinimumOf4ConditionalOperator.java @@ -0,0 +1,43 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.calebfontenot.lab9_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author ASDV2 + */ +public class MinimumOf4ConditionalOperator { + + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + System.out.println("Please enter 4 numbers to find the minimum of the 4: "); + int _1 = scan.nextInt(); + int _2 = scan.nextInt(); + int _3 = scan.nextInt(); + int _4 = scan.nextInt(); + + System.out.println("minimum= " + + ((_1 < _4) + ? (_1 < _3) + ? (_1 < _2) + ? _1 + : _2 + : (_3 < _2) + ? _3 + : _2 + : (_4 < _3) + ? (_4 < _2) + ? _4 + : _2 + : (_3 < _2) + ? _3 + : _2) + ); + } +} diff --git a/lab9_CalebFontenot/src/main/java/com/calebfontenot/lab9_calebfontenot/MinimumOf4DeMorgan.java b/lab9_CalebFontenot/src/main/java/com/calebfontenot/lab9_calebfontenot/MinimumOf4DeMorgan.java index d826652..1177448 100644 --- a/lab9_CalebFontenot/src/main/java/com/calebfontenot/lab9_calebfontenot/MinimumOf4DeMorgan.java +++ b/lab9_CalebFontenot/src/main/java/com/calebfontenot/lab9_calebfontenot/MinimumOf4DeMorgan.java @@ -13,27 +13,26 @@ import java.util.Scanner; */ public class MinimumOf4DeMorgan { - public static void main(String[] args) - { + public static void main(String[] args) { Scanner scan = new Scanner(System.in); - System.out.println("Please neter 3 numbers to find the minimum of the 3:"); - int x = scan.nextInt(); - int y = scan.nextInt(); - int z = scan.nextInt(); + System.out.println("Please enter 4 numbers to find the minimum of the 4: "); + int _1 = scan.nextInt(); + int _2 = scan.nextInt(); + int _3 = scan.nextInt(); + int _4 = scan.nextInt(); - if (! (x > y)) { - if (!(x > z)) { - System.out.println("minimum= " + x); - } else { - System.out.println("minimum= " + z); - } - } else if (!(y > z)) { - System.out.println("minimum= " + y); - } else { - System.out.println("minimum= " + z); + if (! (_1 > _4 || _1 > _3 || _1 > _2)) { // Is 1 the minimum? + System.out.println("minimum= " + _1); + } + else if (! (_2 > _4 || _2 > _3 || _2 > _1)) { // Is 2 the minimum? + System.out.println("minimum= " + _2); + } + else if (! (_3 > _4 || _3 > _2 || _3 > _1)) { // Is 3 the minimum? + System.out.println("minimum= " + _3); + } + else { // All other conditions failed, _4 must be the minimum + System.out.println("minimum= " + _4); } - } - } diff --git a/lab9_CalebFontenot/src/main/java/com/calebfontenot/lab9_calebfontenot/MinimumOf4NestedIfs.java b/lab9_CalebFontenot/src/main/java/com/calebfontenot/lab9_calebfontenot/MinimumOf4NestedIfs.java index 445405c..f1d56cb 100644 --- a/lab9_CalebFontenot/src/main/java/com/calebfontenot/lab9_calebfontenot/MinimumOf4NestedIfs.java +++ b/lab9_CalebFontenot/src/main/java/com/calebfontenot/lab9_calebfontenot/MinimumOf4NestedIfs.java @@ -13,40 +13,48 @@ import java.util.Scanner; */ public class MinimumOf4NestedIfs { - public static void main(String[] args) - { + public static void main(String[] args) { Scanner scan = new Scanner(System.in); + while (true) { + System.out.println("Please enter 4 numbers to find the minimum of the 4: "); + int _1 = scan.nextInt(); + int _2 = scan.nextInt(); + int _3 = scan.nextInt(); + int _4 = scan.nextInt(); - System.out.println("Please neter 3 numbers to find the minimum of the 3:"); - int _1 = 1; //scan.nextInt(); - int _2 = 2; //scan.nextInt(); - int _3 = 3; //scan.nextInt(); - int _4 = 4; //scan.nextInt(); - - if (_1 < _2) { // Is x less than y? - if (_1 < _3) { // Is x less than z? - System.out.println("x is less than z!"); - System.out.println("minimum= " + _1); + if (_1 < _4) { + if (_1 < _3) { + if (_1 < _2) { + System.out.println("minimum= " + _1); + } else { + System.out.println("minimum= " + _2); + } + } else { + if (_3 < _2) { + System.out.println("minimum= " + _3); + } else { + System.out.println("minimum= " + _2); + } + } } else { - System.out.println("z is less than x!"); - System.out.println("minimum= " + _3); + if (_4 < _3) { + if (_4 < _2) { + System.out.println("minimum= " + _4); + } else { + System.out.println("minimum= " + _2); + } + } else { + if (_3 < _2) { + System.out.println("minumum= " + _3); + } else { + System.out.println("minimum= " + _2); + } + } } - } else if (_2 < _3) { // Is y less than z? - System.out.println("y is less than z!"); - System.out.println("minimum= " + _2); - } else { - System.out.println("z is less than y!"); - System.out.println("minimum= " + _3); - } - /* - if (_1 < _4) { - //if ( ) { - } else { - System.out.println("w is less than y!"); - System.out.println("minimum= " + _4); + scan.next(); } - */ + } } diff --git a/lab9_CalebFontenot/src/main/java/com/calebfontenot/lab9_calebfontenot/MinimumOf4WithANDs.java b/lab9_CalebFontenot/src/main/java/com/calebfontenot/lab9_calebfontenot/MinimumOf4WithANDs.java new file mode 100644 index 0000000..e7b631d --- /dev/null +++ b/lab9_CalebFontenot/src/main/java/com/calebfontenot/lab9_calebfontenot/MinimumOf4WithANDs.java @@ -0,0 +1,54 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.calebfontenot.lab9_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author ASDV2 + */ +public class MinimumOf4WithANDs { + + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + System.out.println("Please enter 4 numbers to find the minimum of the 4: "); + int _1 = 4; //scan.nextInt(); + int _2 = 3; //scan.nextInt(); + int _3 = 2; //scan.nextInt(); + int _4 = 1; //scan.nextInt(); +/* + if (_1 < _2) { // Is x less than y? + if (_1 < _3) { // Is x less than z? + //System.out.println("x is less than z!"); + System.out.println("minimum= " + _1); + } else { + //System.out.println("z is less than x!"); + System.out.println("minimum= " + _3); + } + } else if (_2 < _3) { // Is y less than z? + //System.out.println("y is less than z!"); + System.out.println("minimum= " + _2); + } else { + //System.out.println("z is less than y!"); + System.out.println("minimum= " + _3); + } + */ + if (_1 < _4 && _1 < _3 && _1 < _2) { // Is 1 the minimum? + System.out.println("minimum= " + _1); + } + else if (_2 < _4 && _2 < _3 && _2 < _1) { // Is 2 the minimum? + System.out.println("minimum= " + _2); + } + else if (_3 < _4 && _3 < _2 && _3 < _1) { // Is 3 the minimum? + System.out.println("minimum= " + _3); + } + else { // All other conditions failed, _4 must be the minimum + System.out.println("minimum= " + _4); + } + } +}