lab9 complete, (SUBMISSION DOC INCOMPLETE)

This commit is contained in:
Chloe Fontenot 🏳️‍⚧️ 2022-09-21 07:06:06 -05:00
parent 5f825c63f7
commit 59bf3af574
6 changed files with 151 additions and 47 deletions

Binary file not shown.

View File

@ -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();

View File

@ -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)
);
}
}

View File

@ -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);
if (! (_1 > _4 || _1 > _3 || _1 > _2)) { // Is 1 the minimum?
System.out.println("minimum= " + _1);
}
} else if (!(y > z)) {
System.out.println("minimum= " + y);
} else {
System.out.println("minimum= " + z);
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);
}
}
}

View File

@ -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!");
if (_1 < _4) {
if (_1 < _3) {
if (_1 < _2) {
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!");
if (_3 < _2) {
System.out.println("minimum= " + _3);
}
/*
if (_1 < _4) {
//if ( ) {
} else {
System.out.println("w is less than y!");
System.out.println("minimum= " + _4);
System.out.println("minimum= " + _2);
}
*/
}
} else {
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);
}
}
}
scan.next();
}
}
}

View File

@ -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);
}
}
}