Profile Report - Test Your JAVA Programming Skill - Freshers Hire
InCorrect
Write a program to find the second largest number in an array.
Business Rules:
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
InCorrect
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);
}
}
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:
Sample Input 1:
5
Sample Output :
5 is a fibonacci number.
Sample Input 2:
15
Sample Ouput :
15 is not a fibonacci number.
InCorrect
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");
}
}
}
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:
Sample Input :
abcmadamcbamadam
Sample Output :
Longest palindrome in abcmadamcbamadam is abcmadamcba
| 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