Java_30_Questions
Java_30_Questions
-----------------
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.
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.
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);
Formula:
fib(n) = fib(n-1) + fib(n-2)
note: non-recursive solutuon is faster
boolean isFib(int n) {
//write code
}
N8) Write a function to test whether,
given N is prime or not ?
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.
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}
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.
Sample Input/Output-1:
upperCount("www") --> 0
Sample Input/Output-2:
upperCount("WIN") --> 3
Sample Input/Output-1:
asciiSum("AA") --> 130
Sample Input/Output-2:
isPalindrome("aa") --> 97+97=194
Arrays:
-----------------
A2)
Write an efficient function
to find maximum value in the given array.
A3)
Write an efficient function
to find sum of all values in the given array.
// 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));
}