Commit 68ffe40e by Remoba

### Merge branch 'dev' into 'master'

Assignment implementation

See merge request !1
parents 7eee1f7c ded25284
Task1.java 0 → 100644
 import java.util.Scanner; public class Task1 { public static void main(String[] args) { // ----------------- write your code BELOW this line only -------- // your code here (add lines) Scanner myScanner = new Scanner(System.in); int numberA = myScanner.nextInt(); int numberB = myScanner.nextInt(); int numberC = myScanner.nextInt(); int tmp; // Make sure numberA is smaller than numberB if (numberA > numberB) { tmp = numberA; numberA = numberB; numberB = tmp; } // Make sure numberB is smaller than numberC if (numberB > numberC) { tmp = numberB; numberB = numberC; numberC = tmp; // If replaced, Make sure numberB is still bigger than numberA if (numberA > numberB) { tmp = numberA; numberA = numberB; numberB = tmp; } } System.out.println(numberA); System.out.println(numberB); System.out.println(numberC); // ----------------- write your code ABOVE this line only --------- } }
Task2.java 0 → 100644
 import java.util.Scanner; public class Task2 { public static void main(String[] args) { // ----------------- write your code BELOW this line only -------- // your code here (add lines) Scanner myScanner = new Scanner(System.in); int number = myScanner.nextInt(); int divisor = 2; // Iterating over possible divisors from 2 to the number's square root // The divisors will only be primes according to Unique Factorization Theorem while (divisor * divisor <= number) { // If divisible, print the divisor and divide it from the number if ( number % divisor == 0 ) { System.out.println(divisor); number /= divisor; } else { // Only increment the divisor when it no longer divides the number divisor++; } } // The remaining number is the final divisor System.out.println(number); // ----------------- write your code ABOVE this line only --------- } }
Task3.java 0 → 100644
 import java.util.Scanner; public class Task3 { public static void main(String[] args) { // ----------------- write your code BELOW this line only -------- // your code here (add lines) Scanner myScanner = new Scanner(System.in); int numerA = myScanner.nextInt(); int denomA = myScanner.nextInt(); int numerB = myScanner.nextInt(); int denomB = myScanner.nextInt(); // Calculate the numerator and denominator of the result summary int numer = numerA * denomB + denomA * numerB; int denom = denomA * denomB; // Executing the Euclidean algorithm for GCD of the numerator and denominator for fraction reduction int numberA = numer; int numberB = denom; int remainder = numberA % numberB; while (remainder != 0) { numberA = numberB; numberB = remainder; remainder = numberA % numberB; } // numberB is the GCD, Reduce the result fraction numer = numer / numberB; denom = denom / numberB; System.out.println(numer); System.out.println(denom); // ----------------- write your code ABOVE this line only --------- } }
Task4.java 0 → 100644
 import java.util.Scanner; public class Task4 { public static void main(String[] args) { // ----------------- write your code BELOW this line only -------- // your code here (add lines) Scanner myScanner = new Scanner(System.in); int numerIn = myScanner.nextInt(); int denomIn = myScanner.nextInt(); // Executing the Euclidean algorithm for GCD of the numerator and denominator for fraction reduction int numberA = numerIn; int numberB = denomIn; int remainder = numberA % numberB; while (remainder != 0) { numberA = numberB; numberB = remainder; remainder = numberA % numberB; } // numberB is the GCD, Reduce the result fraction int numerOut = numerIn / numberB; int denomOut = denomIn / numberB; numerIn = myScanner.nextInt(); // Get inputs until -1, calculate the summery each loop while (numerIn != -1) { denomIn = myScanner.nextInt(); // Calculate the numerator and denominator of the result summary numerOut = numerIn * denomOut + denomIn * numerOut; denomOut = denomIn * denomOut; // Executing the Euclidean algorithm for GCD of the numerator and denominator for fraction reduction numberA = numerOut; numberB = denomOut; remainder = numberA % numberB; while (remainder != 0) { numberA = numberB; numberB = remainder; remainder = numberA % numberB; } // numberB is the GCD, Reduce the result fraction numerOut = numerOut / numberB; denomOut = denomOut / numberB; numerIn = myScanner.nextInt(); } System.out.println(numerOut); System.out.println(denomOut); // ----------------- write your code ABOVE this line only --------- } }
Task5.java 0 → 100644
 import java.util.Scanner; public class Task5 { public static void main(String args[]) { // ----------------- write your code BELOW this line only -------- // your code here (add lines) Scanner myScanner = new Scanner(System.in); int a = myScanner.nextInt(); int b = myScanner.nextInt(); int c = myScanner.nextInt(); // Make a and b the smallest numbers int tmp; // Make sure that b is bigger than a if (a > b) { tmp = a; a = b; b = tmp; } // Make sure that b is smaller than c if (b > c) { tmp = b; b = c; c = tmp; } System.out.println(a); System.out.println(b); // ----------------- write your code ABOVE this line only --------- } }
Task6.java 0 → 100644
 // You may not change or erase any of the lines and comments // in this file. You may only add lines in the designated // area. import java.util.Scanner; public class Task6 { public static void main(String[] args) { // ----------------- "A": write your code BELOW this line only -------- // your code here (add lines) Scanner myScanner = new Scanner(System.in); int a = myScanner.nextInt(); int b = myScanner.nextInt(); int c = myScanner.nextInt(); int d = myScanner.nextInt(); // Make a and b the smallest numbers int tmp; // Make sure that a is smaller than b if (a > b) { tmp = a; a = b; b = tmp; } // Make sure that b is smaller than c if (b > c) { tmp = b; b = c; c = tmp; // If replaced, Make sure that a is smaller than b again if (a > b) { tmp = a; a = b; b = tmp; } } // Make sure that b is smaller than d if (b > d) { tmp = b; b = d; d = tmp; } System.out.println(a); System.out.println(b); // ----------------- "B" write your code ABOVE this line only --------- } // end of main } //end of class Task6
Task7.java 0 → 100644