Skip to content
This repository has been archived by the owner on Apr 18, 2022. It is now read-only.

EDS Coding Interview #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions java-engineer-1/src/CountingThreading.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,41 @@
/**
* Write a java code that takes input of a number N, and outputs counting from 1 to N in "N" seconds. Use Threads.
*/
public class CountingThreading {
import java.util.*;

public class CountingThreading implements Runnable{

int N;
CountingThreading(int N){
this.N = N;
}

public static void main(String[] args) throws Exception{

System.out.println("Hello from CountingThreading.java");
System.out.println("Hello from CountingThreading.java\n");
System.out.print("Enter N: ");
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
sc.close();
CountingThreading ct = new CountingThreading(num);
new Thread(ct).start();

}

@Override
public void run() {
int i = 1;
while(i <= N){
System.out.println(i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
i++;
}

}

}
19 changes: 19 additions & 0 deletions java-engineer-1/src/FizzBuzz.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@ public class FizzBuzz {
public static void main(String[] args) throws Exception{

System.out.println("Hello from FizzBuzz.java");

for(int i = 1; i <= 100; i++)
{
if(i % 15 == 0)
{
System.out.println("FizzBuzz");
}
else if(i % 5 == 0)
{
System.out.println("Buzz");
}
else if(i % 3 == 0)
{
System.out.println("Fizz");
}
else{
System.out.println(i);
}
}

}

Expand Down
17 changes: 16 additions & 1 deletion java-engineer-1/src/Recursion.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import java.util.Scanner;

/**
* Write a recursive function that takes a string as input and returns the reversed string.
*/
Expand All @@ -6,7 +8,20 @@ public class Recursion {
public static void main(String[] args) throws Exception{

System.out.println("Hello from Recursion.java");
Scanner sc = new Scanner(System.in);
System.out.print("Enter a word: ");
String word = sc.next();
sc.close();
String word1 = reverse(word);
System.out.println("The reverse of '" + word + "' is '" + word1 + "'.");

}

public static String reverse(String word){
if(word.length() <= 1)
{
return word;
}
return reverse(word.substring(1)) + word.charAt(0);
}
}

31 changes: 29 additions & 2 deletions java-engineer-1/src/ReverseWords.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
/**
* Write a recursive function that takes a string as input and returns the reversed string.
*/
import java.util.*;

public class ReverseWords {

public static void main(String[] args) throws Exception{

System.out.println("Hello from ReverseWords.java");

System.out.println("Hello from ReverseWords.java\n");
System.out.print("Enter a string: ");
Scanner sc = new Scanner(System.in);
String word = sc.nextLine();
String rword = reverse(word);
System.out.println("The reverse of '" + word + "' is '" + rword + "'.");
sc.close();
}

public static String reverse(String word){
int numWords = 0;
String res = "";
for(int i = 0; i < word.length(); i++){
if(word.charAt(i) == ' '){
numWords++;
}
}
String words[] = new String[numWords + 1];
words = word.split(" ");
String ans[] = new String[numWords + 1];
for(int i = 0; i < words.length; i++){
ans[i] = words[words.length - 1 -i];
}
for(int i = 0; i < words.length; i++){
res += ans[i] + " ";
}
return res.substring(0, word.length());
}

}