GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - rradfar/codewars-java: Codewars Java solutions

BranchesTags
Open more actions menu

Latest commit

 

History

11 Commits
11 Commits

Folders and files

NameName
Last commit message
Last commit date
images
images
 
 
.gitignore
.gitignore
 
 
README.md
README.md
 
 

Repository files navigation

java

Codewars Java Solutions

Challenges

Kyu Questions
8 Beginner Series #2 Clock
8 Century From Year
8 Even or Odd
6 Find the Odd Int
8 Is n Divisible by x and y?
8 Keep Hydrated!
6 Multiples of 3 or 5
8 Multiply
7 Vowel Count

Beginner Series #2 Clock

The clock shows h hours (0 <= h <= 23), m minutes (0 <= m <= 59) and s seconds (0 <= s <= 59) after midnight. Your task is to write a function which returns the time since midnight in milliseconds.

Examples:

h = 0, m = 0, s = 0 -> res = 0
h = 0, m = 1, s = 1 -> res = 61000
h = 1, m = 0, s = 1 -> res = 3601000
public class Clock {
  public static int Past(int h, int m, int s) {
    // Your solution
  }
}
Solution
public class Clock {
  public static int Past(int h, int m, int s) {
    return ((h * 60 * 60) + (m * 60) + s) * 1000;
  }
}

⬆ Back to Top

Century From Year

The first century spans from the year 1 up to and including the year 100, The second - from the year 101 up to and including the year 200, etc. Given a year, return the century it is in.

public class Solution {
  public static int century(int number) {
    // Your solution
  }
}
Solution
public class Solution {
  public static int century(int number) {
    return (int)(Math.ceil(number / 100.0)); 
  }
}

⬆ Back to Top

Even or Odd

Create a function that takes an integer as an argument and returns "Even" for even numbers or "Odd" for odd numbers.

public class EvenOrOdd {
  public static String even_or_odd(int number) {
    // Your solution
  }
}
Solution
public class EvenOrOdd {
  public static String even_or_odd(int number) {
    return number % 2 == 0 ? "Even" : "Odd";
  }
}

⬆ Back to Top

Find the Odd Int

Given an array of integers, find the one that appears an odd number of times. There will always be only one integer that appears an odd number of times.

public class FindOdd {
  public static int findIt(int[] a) {
    // Your solution
  }
}
Solution
import static java.util.Arrays.stream;

public class FindOdd {
  public static int findIt(int[] arr) {
    return stream(arr).reduce(0, (a, b) -> a ^ b);
  }
}

⬆ Back to Top

Is n Divisible by x and y?

Create a function that checks if a number n is divisible by two numbers x AND y. All inputs are positive, non-zero digits.

public class DivisibleNb {
  public static boolean isDivisible(long n, long x, long y) {
    // Your solution
  }
}
Solution
public class DivisibleNb {
  public static boolean isDivisible(long n, long x, long y) {
    return (n % x == 0) && (n % y == 0);
  }
}

⬆ Back to Top

Keep Hydrated!

Nathan loves cycling. Because Nathan knows it is important to stay hydrated, he drinks 0.5 litres of water per hour of cycling. You get given the time in hours and you need to return the number of litres Nathan will drink, rounded to the smallest value.

public class KeepHydrated {
  public int Liters(double time) {
    // Your solution
  }
}
Solution
public class KeepHydrated {
  public int Liters(double time) {
    return (int)(time / 2);
  }
}

⬆ Back to Top

Multiples of 3 or 5

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Finish the solution so that it returns the sum of all the multiples of 3 or 5 below the number passed in.

Note: If the number is a multiple of both 3 and 5, only count it once. Also, if a number is negative, return 0.

public class Solution {
  public int solution(int number) {
    // Your solution
  }
}
Solution
public class Solution {
  public int solution(int number) {
    int sum = 0;
    for (int i = 3; i < number; i++) {
      if (i % 3 == 0 || i % 5 == 0) {
        sum += i;
      }
    }
    return sum;
  }
}

⬆ Back to Top

Multiply

This code does not execute properly. Try to figure out why.

public class Multiply {
  public static Double multiply(Double a, Double b) {
    return a * b
  }
}
Solution
public class Multiply {
  public static Double multiply(Double a, Double b) {
    return a * b;
  }
}

⬆ Back to Top

Vowel Count

Return the number (count) of vowels (a, e, i, o, u) in the given string. The input string will only consist of lower case letters and/or spaces.

public class Vowels {
  public static int getCount(String str) {
    // Your solution
  }
}
Solution
public class Vowels {
  public static int getCount(String str) {
    int vowelsCount = 0;
    String vowels = "aeiou";
    for (int i = 0; i < str.length(); i++) {
      if (vowels.contains(String.valueOf(str.charAt(i)))) {
        vowelsCount++;
      }
    }
    return vowelsCount;
  }
}

⬆ Back to Top

About

Codewars Java solutions

Topics

codewarscodewars-solutionsjavajava-challenges

Resources

Readme
Activity

Stars

2 stars

Watchers

1 watching

Forks

3 forks
Report repository

Releases

Packages

Contributors

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.