Skip to content

Commit

Permalink
Merge pull request #10 from 101zh/unit4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
101zh authored Oct 25, 2023
2 parents 9c696ab + 16a9d20 commit 148e7e4
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/main/java/Unit4/U4_L2_Activity_One.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
50 changes: 50 additions & 0 deletions src/main/java/Unit4/U4_L2_Activity_Three.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
23 changes: 23 additions & 0 deletions src/main/java/Unit4/U4_L2_Activity_Two.java
Original file line number Diff line number Diff line change
@@ -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();

}
}

0 comments on commit 148e7e4

Please sign in to comment.