diff --git a/src/main/java/Unit4/U4_L2_Activity_One.java b/src/main/java/Unit4/U4_L2_Activity_One.java new file mode 100644 index 0000000..7adba91 --- /dev/null +++ b/src/main/java/Unit4/U4_L2_Activity_One.java @@ -0,0 +1,22 @@ +package Unit4; + +import java.util.Scanner; + +public class U4_L2_Activity_One { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.println("Enter two numbers: "); + int num1 = scanner.nextInt(); + int num2 = scanner.nextInt(); + if(num1%2==0){ + num1++; + } + + while(num1<=num2){ + System.out.println(num1); + num1+=2; + } + + scanner.close(); + } +} diff --git a/src/main/java/Unit4/U4_L2_Activity_Three.java b/src/main/java/Unit4/U4_L2_Activity_Three.java new file mode 100644 index 0000000..4ce648a --- /dev/null +++ b/src/main/java/Unit4/U4_L2_Activity_Three.java @@ -0,0 +1,50 @@ +package Unit4; + +import java.util.Scanner; + +public class U4_L2_Activity_Three { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + int anotherLocation = 1; + double largestLatitude = -90.0; + double largestLongitude = -180.0; + double smallestLatitude = 90.0; + double smallestLongitude = 180.0; + + while (anotherLocation == 1) { + System.out.println("Please enter the longitude:"); + double longitude = scanner.nextDouble(); + System.out.println("Please enter the latitude:"); + double latitude = scanner.nextDouble(); + + boolean longitudeIsValid = -180.0 <= longitude && longitude <= 180.0; + boolean latitudeIsValid = -90.0 <= latitude && latitude <= 90.0; + + if (longitudeIsValid && latitudeIsValid) { + if (latitude > largestLatitude) + largestLatitude = latitude; + if (latitude < smallestLatitude) + smallestLatitude = latitude; + + if (longitude > largestLongitude) + largestLongitude = longitude; + if (longitude < smallestLongitude) + smallestLongitude = longitude; + + } else { + System.out.println("Incorrect Latitude or Longitude "); + } + System.out.println("Would you like to enter another location?"); + + anotherLocation = scanner.nextInt(); + } + + System.out.println("Farthest North: " + largestLatitude); + System.out.println("Farthest South: " + smallestLatitude); + System.out.println("Farthest East: " + largestLongitude); + System.out.println("Farthest West: " + smallestLongitude); + + scanner.close(); + } +} diff --git a/src/main/java/Unit4/U4_L2_Activity_Two.java b/src/main/java/Unit4/U4_L2_Activity_Two.java new file mode 100644 index 0000000..729a0b3 --- /dev/null +++ b/src/main/java/Unit4/U4_L2_Activity_Two.java @@ -0,0 +1,23 @@ +package Unit4; + +import java.util.Scanner; + +public class U4_L2_Activity_Two { + public static void main(String[] args){ + Scanner scanner = new Scanner(System.in); + + System.out.println("Enter a positive integer:"); + System.out.print("> "); + int num = scanner.nextInt(); + + int index=0; + while(num>0){ + System.out.println((num%10)* (int) Math.pow(10, index)); + index++; + num/=10; + } + + scanner.close(); + + } +}