Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .idea/lab-java-basics.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

207 changes: 207 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions src/Basics.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
public class Basics {
public static void main(String[] args) {
// Declare and initialize a list of integers.
int[] list = {12, 90, 56, 1, 2, 78};

// Call methods to calculate the difference between the largest and smallest element,
// and to find the two smallest elements in the list.
diffLargestAndSmallest(list);
firstAndSecondSmallest(list);
}

/**
* Method to calculate the difference between the largest and smallest element in an array.
* @param list The array of integers.
*/
public static void diffLargestAndSmallest(int[] list) {
// Initialize variables to store the smallest and largest elements.
int smallest = list[0];
int largest = list[0];

// Check that the list is not empty.
if (list.length > 0) {
// Iterate through each element in the list.
for (int j : list) {
// Update the smallest element if the current element is smaller.
if (smallest > j) {
smallest = j;
}
// Update the largest element if the current element is larger.
if (largest < j) {
largest = j;
}
}
}

// Calculate the difference between the largest and smallest elements.
int diff = largest - smallest;

// Print the result.
System.out.println("The difference between the smallest (" + smallest + ") and largest (" + largest + ") integer in this list is: " + diff);
}

/**
* Method to find the two smallest elements in an array.
* @param list The array of integers.
*/
public static void firstAndSecondSmallest(int[] list) {
// Check that the list contains at least two elements.
if (list.length < 2) {
System.out.println("Array must have at least two elements.");
return;
}

// Initialize variables to store the two smallest elements.
int firstSmallest = Integer.MAX_VALUE;
int secondSmallest = Integer.MAX_VALUE;

// Iterate through each element in the array.
for (int i : list) {
// Update the first smallest element if the current element is smaller.
if (firstSmallest > i) {
secondSmallest = firstSmallest;
firstSmallest = i;
}
// Update the second-smallest element if the current element is smaller than the second smallest but larger than the first smallest.
else if (secondSmallest > i) {
secondSmallest = i;
}
}

// Print the two smallest elements.
System.out.println("First smallest: " + firstSmallest);
System.out.println("Second smallest: " + secondSmallest);
}
}
24 changes: 24 additions & 0 deletions src/Company.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
public class Company {
public static void main(String[] args) {
// Create an array to hold 10 Employee objects.
Employee[] team = new Employee[10];

// Initialize each element of the array with an Intern object.
team[0] = new Intern("Salvatore", 18, 20000);
team[1] = new Intern("Céline", 22, 3400);
team[2] = new Intern("Alex", 24, 4200);
team[3] = new Intern("Elodie", 19, 6500);
team[4] = new Intern("Rosca", 27, 1500);
team[5] = new Intern("Ahmad", 33, 15000);
team[6] = new Intern("Cesar", 45, 16000);
team[7] = new Intern("Elise", 24, 2000);
team[8] = new Intern("Tino", 50, 13000);
team[9] = new Intern("Sébastien", 26, 10000);

// Iterate through each Employee in the team array.
for (Employee member : team) {
// Print the string representation of each Employee.
System.out.println(member.toString());
}
}
}
Loading