DEV Community

Neelakandan R
Neelakandan R

Posted on

My First interview in Suave Technologies as Fresher

It was the first interview I attended as a Java Developer. I had some fear inside me before attending the interview, but after it, I felt much better. Success or failure doesn't matter — what matters is that we give our best effort.

1.The first round was about choosing the correct output.

2.The second round was focused on coding. I was asked to solve a programming problem as part of this round.

java Coding Question: Fibonacci Prime Sum Checker

Problem Statement:

Write a Java program that does the following:

==>Accepts three integer inputs from the user:

==>start: the starting index of the Fibonacci sequence

==>end: the ending index of the Fibonacci sequence

==>limit: a number to compare the final sum against

==>Generates Fibonacci numbers from index start to end (inclusive).

==>From these Fibonacci numbers:

==>Find which numbers are prime

==>Calculate the sum of these prime Fibonacci numbers

Finally:

==>If the sum is less than the limit, print "no"

==>Otherwise, print "yes"

package pratice; import java.util.Scanner; public class fabonacci_series { static int total = 0; // Make total a static class variable public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter start value:"); int start = sc.nextInt(); System.out.println("Enter end value:"); int end = sc.nextInt(); System.out.println("Enter limit value:"); int limit = sc.nextInt(); findficser(start, limit, end); if (total < limit) { System.out.println("no"); } else { System.out.println("yes"); } sc.close(); } private static void findficser(int start, int limit, int end) { int x = 1; int y = 0; int z = 0; for (int i = 0; i <limit; i++) { if (i >= start && i <= end) { if (z < limit) { System.out.print(z+" "); findprime(z); } } z = x + y; x = y; y = z; }System.out.println(); } private static void findprime(int z) { boolean prime = true; if (z <= 1) { prime = false; } else { for (int div = 2; div <= z/2; div++) { if (z % div == 0) { prime = false; break; } } } if (prime) { total =total+ z; } } } 
Enter fullscreen mode Exit fullscreen mode

OutPut:
Enter start value:
2
Enter end value:
2
Enter limit value:
9
0 1 1 2 3 5 8
yes

Top comments (0)