Ad
Code
Diff
  • object FindMultiples:
    
      def findMultiples(n: Int): Int = 
        Seq.range(0, n).filter(i => i % 4 == 0 || i % 6 == 0).sum
    
    
    • object FindMultiples:
    • def findMultiples(n: Int): Int =
    • (for (i <- 0 until n by 2 if i % 4 == 0 || i % 6 == 0) yield i).sum
    • Seq.range(0, n).filter(i => i % 4 == 0 || i % 6 == 0).sum
Code
Diff
  • object FindMultiples:
    
      def findMultiples(n: Int): Int = 
          (for (i <- 0 until n by 2 if i % 4 == 0 || i % 6 == 0) yield i).sum 
    
    
    • def find_multiples(n):
    • total = 0
    • for i in range(0, n, 2):
    • if i % 4 == 0 or i % 6 == 0:
    • total += i
    • return total
    • object FindMultiples:
    • def findMultiples(n: Int): Int =
    • (for (i <- 0 until n by 2 if i % 4 == 0 || i % 6 == 0) yield i).sum
Code
Diff
  • object Adder:
    
      def addAllContent(numbers: Array[Int]): Int = numbers.sum
    
    • public class Adder {
    • public static int AddAllContent(int[] numbersToAdd) {
    • int sum = 0;
    • object Adder:
    • for (int i : numbersToAdd)
    • sum += i;
    • return sum;
    • }
    • }
    • def addAllContent(numbers: Array[Int]): Int = numbers.sum
Fundamentals
Arrays
Strings
Code
Diff
  • object FindTRex:
      def containsTRex(things: Array[String]): Boolean = things.contains("Tyrannosaurus")
    
    • public class findT_Rex {
    • public static boolean containsT_Rex(String[] things) {
    • //insert code!
    • return true;
    • }
    • }
    • object FindTRex:
    • def containsTRex(things: Array[String]): Boolean = things.contains("Tyrannosaurus")
Code
Diff
  • object Practice01:
    	def reverse(input: String): String = input.reverse
    
    • //import java.util.Scanner;
    • import java.lang.StringBuilder;
    • public class Practice01{
    • public static String reverse(String input) {
    • /*Scanner sc = new Scanner(System.in);
    • System.out.println("Give the desired string to be reversed :");
    • String e = sc.nextLine();*/
    • return new StringBuilder(input).reverse().toString();
    • }
    • }
    • object Practice01:
    • def reverse(input: String): String = input.reverse