Commit 68ffe40e by Remoba

Merge branch 'dev' into 'master'

Assignment implementation

See merge request !1
parents 7eee1f7c ded25284
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 ---------
}
}
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 ---------
}
}
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 ---------
}
}
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 ---------
}
}
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 ---------
}
}
// 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
// You may not change or erase any of the lines and comments
// in this file. You may only add lines.
public class Task7 {
public static void main(String[] args) {
// ----------------- write any code BELOW this line only --------
// your code here (add lines)
boolean isVerified = true;
int numberA = 0, numberB = 0, numberC = 0, numberD = 0;
// Creates the 16 possible combinations
while (numberA <= 1 & isVerified) {
numberB = 0;
while (numberB <= 1 & isVerified) {
numberC = 0;
while (numberC <= 1 & isVerified) {
numberD = 0;
while (numberD <= 1 & isVerified) {
int a, b, c, d;
a = numberA;
b = numberB;
c = numberC;
d = numberD;
// ----------------- write any code ABOVE this line only ---------
// ----------------- copy here the code from Task 6 that is between
// ----------------- the comments "A" and "B"
// code from Task 6 here
// 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;
}
// ----------------- end of copied code from Task 6
// ----------------- write any code BELOW this line only --------
// your code here (add lines)
if (a > c | a > d | b > c | b > d) {
isVerified = false;
}
numberD++;
}
numberC++;
}
numberB++;
}
numberA++;
}
if (isVerified) {
System.out.println("verified");
} else {
System.out.println((numberA - 1));
System.out.println((numberB - 1));
System.out.println((numberC - 1));
System.out.println((numberD - 1));
}
// ----------------- write any code ABOVE this line only ---------
} // end of main
} //end of class Task7
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment