Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
1 views

Java_30_Questions

Interviews questions java core.

Uploaded by

Abhinav Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Java_30_Questions

Interviews questions java core.

Uploaded by

Abhinav Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Number Handling:

-----------------

N1) Write a function to test whether


given number N is odd or even.
If given number is odd number, return "odd";
If given number is even number, return "even";
String isOddEven(int n) {
// write code
}

N2) Write a function to test whether


given number N is a multiple of X or not.
Return true, if given 'n' is a multiple of x.
Return false,if given 'n' is not a multiple of x.

boolean isMulOfX(int n, int x) {


// write code
}

Sample Input/Output-1:
isMulOfX(10,2) --> true.
Because, 10 is a multiple of 2.

Sample Input/Output-2:
isMulOfX(10,3) --> false.
Because, 10 not is a multiple of 3.

Sample Input/Output-3:
isMulOfX(10,10) --> true.
Because, 10 is a multiple of 10.

N3) Write a function to find the


factorial of given number n.

Note: 0! = 1
1! = 1
n! = n* (n-1)! , if n >1
n! = 1, if n ==0 or n ==1

int fact(int n) {
// write code
}
N4)
Write a function to find the
ncr value, given n and r.

Note: nCr(n,r) = n!/ ( (n-r)!*r!)

int ncr(int n, int r) {


// write code
}

Sample Input/Output-1:
nCr(5,2) --> 5!/((3!)*(2!)) =10

Sample Input/Output-2:
nCr(5,1) --> 5!/((4!)*(1!)) =5

GENERATION OF SERIES:

N5) Write a function to find area of Square, given the value 'a':
float findArea(int a);
Write a function to find
the volume of Cube, given the value 'a':
float findVolume(int a);

Write a function to find


Area of Rectangle, the value 'l' and 'b':
float findRectArea(float length, float breadth);

Write a function to find Area of Circle,


given radius 'r' as input :
float findCircleArea(float radius);

N6) Generation of fibbonacci series:


Print the first n numbers in fibbonacci series.
Note:
Fibbonacci series:
0,1, 1, 2, 3, 5, 8, 13, 21 .....

Formula:
fib(n) = fib(n-1) + fib(n-2)
note: non-recursive solutuon is faster

int fib(int n){


// write code
}

N7) Write a function to test whether


given N is a fibbonacci number or not.
Return true, if n is a fibbonacci number.
Return false, if n is NOT a fibbonacci number.
note: better solution needed.

boolean isFib(int n) {
//write code
}
N8) Write a function to test whether,
given N is prime or not ?

note: use better for loop

boolean isPrime(int N) {
// write code
}

Sample Input/Output-1:
isPrime(17) --> true

Sample Input/Output-2:
isPrime(15) --> false
N9) Write a function to generate range of numbers
from start to end, incremented by step value.
Return all integers in an int array.
Note: end value not to be included in output.

int[] range(int start, int end, int step);

Sample Input/Output-1:
range(1, 10, 1)
answer = {1,2,3,4,5,6,7,8,9}

Sample Input/Output-2:
range(0, 11, 2)
answer = {0,2,4,6,8,10}

Sample Input/Output-3:
range(1, 21, 10)
answer = {1,11}

N10) Write a function to find compound interest.

float findCI(float p, float n, float r){


// write code
}
String Handling:
-----------------

S1) Write a function to find reverse of a string:


String reverse(String s){
// write code
}

S2) Write a function to check whether


given String is palindrome or not.

boolean isPalindrome(String s){


// write code
}

Sample Input/Output-1:
isPalindrome("wow") --> true

Sample Input/Output-2:
isPalindrome("www") --> true

Sample Input/Output-3:
isPalindrome("win") --> false
S3) Write a function to count number of Uppercases
letters in the given String and return the same.

int upperCount(String s){


// write code
}

Sample Input/Output-1:
upperCount("www") --> 0

Sample Input/Output-2:
upperCount("WIN") --> 3

S4) Write a function to find the


ASCII sum of all characters in a String.

int asciiSum( String s){


// write code
}

Sample Input/Output-1:
asciiSum("AA") --> 130

Sample Input/Output-2:
isPalindrome("aa") --> 97+97=194

S5) Write a function to Count the


number of words in the given String
and return the same.

int wordCount( String sentence){


// write code
}
S6) Write a function to get all the words
in the given sentence.
Return the words as a String array.

String[] getAllWords(String sentence){


// write code
}
S7) Write a function to get
middle three chars in
each word of the given sentence and
return as an String array.

String[] getAllwordsFML( String sentence){


// write code
}
Note: length of the each word is always odd.
S8) Write a function to find how many times,
the string x, is occuring in the given string s,
and return the answer.

int getKMPCount(String s, String x){


//write code
}
S9) Write a function to validate the email.
Return true, if it is a valid email.
Return false, if it is a invalid email.
Valid email has the following format:
word@word.word.word
Example:
cdio@veltech.edu.in
cab@vtu is an invalid email.

boolean isValidEmail(String s){


//write code
}
//ref
https://howtodoinjava.com/java/regex/java-regex-validate-email-address/

S10) Write a function to validate the URL.


Return true, if it is a valid URL.
Return false, if it is a invalid URL.
Valid URL has the following format:
word.word.word
Note: word cannot have space in them.
Example:
"veltech.edu.in" is a valid URL.
"hello.com" is an invalid URL.

boolean isValidURL(String s){


//write code
}

Arrays:
-----------------

A1) Write an efficient function


to find minimum value in the given array.

int findMin(int a[]){


// write code
}
int findMin(int a[][]){
// write code
}

A2)
Write an efficient function
to find maximum value in the given array.

int findMax(int a[]){


// write code
}

int findMax(int a[][]){


// write code
}

A3)
Write an efficient function
to find sum of all values in the given array.

int findSum(int a[]){


// write code
}
int findSum(int a[][]){
// write code
}

A4) Write a function to find sum of two matrix


and return the resulting matrix.

int[][] addMatrix( int a[][], int b[][]){


// write code
}

A5) Write a function to multiply two matrix


and return the resulting matrix.
int[][] multiplyMatrix( int a[][], int b[][]){
// write code
}

A6) Write a function to perform given operation


on all elements of the matrix.
Modify given matrix, using x value, based on operator op.
Input operator op, can be '+' or '-' or '*' or '/' or '%'.

int[][] modifyMatrix(int a[][], int x,char op){


//write code
}

A7) Implement Kedene algorithm:


Write a function to find the
maximal subarray sum.

// Java program
// to print largest contiguous array sum
public class A7Kedene {
public static void main (String[] args)
{
int [] a = {-2, -3, 4, -1, -2, 1, 5, -3};
System.out.println("Max contiguous sum =" +
maxSubArraySum(a));
}

A8) Make all array elements equal just by using


decrement by 1 operation or
increment by 1 operation.
You need to make all equal to the minvalue in the array.
And, return the total number of operations needed
to make all the elements equal.
Note: Return the answer, without actually performing
the above operation.
int makeEqual(int a[]) {
//write code
}

A9) Find the number of longest increasing


sub sequences (LISS) found in the given array
and return the same.

int countOfLISS(int a[]) {


//write code
}

A10) Find the number of longest decreasing


sub sequence (LDSS) found in the given array
and return the same.

int countOfLDSS(int a[]) {


//write code
}

You might also like