Profile Report - Test Your JAVA Programming Skill - Freshers Hire

Candidate Details
user-img
Overall competency
Fail
0%
Assessment Details
Test Details

Candidate Score
Answer Summary
Question 1 : Second largest number in an array

InCorrect

Write a program to find the second largest number in an array.

Business Rules:

  1. Array should get values dynamically from user as Input
  2. Input values should be integers.
  3. All the 5 input numbers should be entered
  4. Print the message "INVALID INPUT" when input  is insuffient.
  5. Print the message "INVALID INPUT" when input is not an integer

Note: Please enter inputs one by one as mentioned below

Sample Input 1: 

6

1

5

7

3

Sample Output:

Second largest number in given array is 6

Sample Input 2

a

B

5

-9

e

Sample Output:

INVALID INPUT

 

Submitted Code

InCorrect

Main.java
 import java.util.*;
import java.io.*;
class LargestNum
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		
		int arr[] = new int[5];
		int max1 = 0, max2 = 0;
			
		System.out.println("Enter 5 numbers : ");
		for(int i=0; i<5; i++)
		{
				arr[i] = sc.nextInt();
				
				if(arr[i]>max1)
					max1 = arr[i];
		}	
	
		for(int i=0; i<5; i++)
		{
			if(arr[i]max2)
					max2 = arr[i];
		}	
		
		System.out.println("Second largest number in given array is "+max2);		
		
	}
} 
Question 2 : Fibonacci number

InCorrect

Write a Program to test a given number is Fibonacci or not?

Explanation: Fibonacci numbers are the numbers in which each number is the sum of the two preceding numbers. For example 1, 1, 2, 3, 5, 8, 13, 21, 34, ...The first two numbers in the Fibonacci sequence are  0 and 1, as starting point of the sequence

Hint: A positive integer n is a Fibonacci number if and only if one of (5n2 + 4) or (5n2 - 4) is a perfect square.

Business Rules: 

  1. Input should be only positive Integer.
  2. Print the message "INVALID INPUT" when input is wrong.

Sample Input 1:

5

Sample Output :

5 is a fibonacci number.

Sample Input 2:

15

Sample Ouput : 

15 is not a fibonacci number.

Submitted Code

InCorrect

Main.java
 import java.util.*;
import java.util.*;
class Fibonacci
{ 
	public static void main(String args[])  
	{   
		 Scanner sc =new Scanner(System.in);  
		 System.out.println("Enter Number : "); 
		 int n = sc.nextInt();   
		 if(n<0)
			System.out.println("INVALID INPUT");
		 int x = (5*n*n) + 4; 
		 int y = (5*n*n) - 4;  
		 if(isInt(sqrt(x)) || isInt(sqrt(y)))
		 {   
		 System.out.println(n+" is a Fibonacci number"); 
		 } 
	} 
} 
Question 3 : Longest Palindrome in a given string

Not Attempted

Write a program to find the longest palindrome present in a given string

Explanation: A palindrome is a word, phrase or other sequence of characters which reads the same backward as forward, such as madam. For example, in the string abcba, the longest palindrome is abcba and similarly in abcmadamcbamadam, the longest palindrome is abcmadamcba.

Business Rules: 

  1. Input string should contain only alphabets
  2. Input string is case sensitive (ex: M and m are different)
  3. Print a message "INVALID INPUT" when input is wrong. 

Sample Input : 

abcmadamcbamadam

Sample Output :

Longest palindrome in abcmadamcbamadam  is abcmadamcba

Test case execution
Testcase Purpose Actual Input Expected Output Obtained Output Status
No
NO
NO
NO
False

Report generated time : 27-05-2019 01:14:42

Powered by banyan-logo