Warm up

E1

Write a program that finds all the primes below the number given from Scanner. Create one version that uses the naive approach and if you want a bigger challenge, write another version that uses Sieve of Eratosthenes algorithm. Test your program by passing in 100 and ensure that your program still works if you pass any other number as well.

What is a naive approach?

Naive approach is nothing but a simplistic solution without much thought to improve performance. For e.g., you may use two loops; one outer and one inner to solve this problem. The outer loop iterates over all the numbers and for every execution of the outer loop, the inner loop may execute completely upto the index value of the outer loop to see if any there is any number below the outer index number which can divide it.

E2

Find if a given string from the Scanner input is a palindrome or not? For e.g., if the input string is ‘madam’ then it is a palindrome if the input string is ‘light’ then it is not a palindrome. The program should be in a continuous loop expecting user input.

Problems from Project Euler: https://projecteuler.net/

E3

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

Write a program to generate the first 100 numbers of this sequence

E4

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.

Find the sum of all the multiples of 3 or 5 below 1000.

HackerRank Contest Link

www.hackerrank.com/mbcc-java-journey-1-practice-1

Other Coding Websites

results matching ""

    No results matching ""