Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loops and version control Lab1 #60

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
57 changes: 57 additions & 0 deletions src/MagidLab1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
public class MagidLab1 {
public static int differenceBetweenLargestAndSmallest(int[] array) {

if (array.length == 0) {
System.out.println("There was a problem with the array");
}

int largest = array[0];
int smallest = array[0];

for (int i = 1; i < array.length; i++) {
if (array[i] > largest) {
largest = array[i];
}

if (array[i] < smallest) {
smallest = array[i];
}
}

return largest - smallest;
}

// Lab1 ii
public static void findFirstAndSecondSmallest(int[] array) {
int min = array[0];
int secondMin = array[0];
for (int i = 1; i < array.length; i++) {
if (array[i] < min) {
secondMin = min;
min = array[i];
} else if (array[i] < secondMin) {
secondMin = array[i];
}
System.out.println(array[i]);
}

}

// Lab1 iii


public static double mathematicalProblems(double x, double y) {
double result = 0.0;
double xPow = x * x;
double loopVariable = 1;
for (int i = 0; i < 2; i++) {
loopVariable = loopVariable * (4 * y / 5 - x);
}
result = xPow + loopVariable;
return result;

}
}



15 changes: 15 additions & 0 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static void main(String[] args) {
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
// to see how IntelliJ IDEA suggests fixing it.
System.out.print("Hello and welcome!");

for (int i = 1; i <= 5; i++) {
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
System.out.println("i = " + i);
}
}
}