Wipro PJP PRP Sample Coding Questions and Solutions
1.Silver number program
import java.util.*;
import java.io.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int k = sc.nextInt();
int l= sc.nextInt();
int m = sc.nextInt();
int b = sumofsilver( k, l, m);
System.out.println(b);
}
public static int sumofsilver(int input1,int input2,int input3){
char[] x =
(String.valueOf(input1)+String.valueOf(input2)+String.valueOf(input3)).toCharArray();
int a =0,j;
for(j=0;j<x.length;j++)
if((x[j]=='7')||(x[j]=='8')||(x[j]=='9'))a++;
else if((x[j]=='1')||(x[j]=='2')||(x[j]=='3'))a=a+3;
else if((x[j]!='0'))a=a+2;
return a;
}
}
2.Succesive Factor program
import java.io.*;
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
String b = finduccesivefactor(a);
System.out.println(b);
}
public static String finduccesivefactor(int input1){
int x = (int)(Math.sqrt(input1));
if(x*(x+1)==input1){
return "T"+x+""+(x+1);
}
else{
int f=0;
for(int i =2;i<=input1/2;i++){
if(input1%i==0){
f=1;
break;
}
}
if(f==0&&input1>1){
return "Tisprime";
}
else{
return "FNotPrime";
}
}
}
}
3.String Task
import java.io.*;
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String a = sc.nextLine();
String b = ModifyString(a);
System.out.println(b);
}
public static String ModifyString(String input1){
String s = input1.replaceAll("[aeiouyAEIOUY]","");
s = s.toLowerCase();
StringBuffer sol = new StringBuffer();
for(int i =0;i<s.length();i++){
sol.append("*");
sol.append(s.charAt(i));
}
String result = sol.toString();
return result;
}
}
4.Math Olympiad
String[] splitArray1 = input1.split(" ");
int[] array1 = new int[splitArray1.length];
for (int i = 0; i < splitArray1.length; i++) {
array1[i] = Integer.parseInt(splitArray1[i]);
}
int a=array1[0];
int b=array1[1];
String[] splitArray = input2.split(" ");
int[] array = new int[splitArray.length];
int count=0;
for (int i = 0; i < splitArray.length; i++) {
array[i] = Integer.parseInt(splitArray[i]);
}
for (int i = 0; i < array.length; i++) {
if (array[i]>=array[b-1])
count++;
}
return count;
5.Advance constraints
static int findAdvancedConstrains(String input1,String input2){
int len=Integer.parseInt(Character.toString(input1.charAt(0)));
int k=Integer.parseInt(Character.toString(input1.charAt(2)));
int count=0;
String []str=input2.split(" ");
int []str2=new int[str.length];
System.out.println(str2[k]);
for(int i=0;i<str.length;i++){
str2[i]=Integer.parseInt(Str[i]);
}
int kelement=str2[k];
for(int i=0;i<str2.length;i++){
if(str2[i]>=kelement){
count++;
}
}
6.ISEmirp
public static int countEmirp(int[] input1, int input2) {
int count = 0;
int res;
for(int i = 0; i < input1.length; i++) {
res = reverse(input1[i]);
if(res != input1[i]) {
if(isPrime(res) == true)
count++;
}
}
return count;
}
public static int reverse(int x)
{
int rev = 0;
while (x > 0)
{
rev = (rev * 10) + x % 10;
x = x / 10;
}
return rev;
}
public static boolean isPrime(int n)
{
// Corner case
if (n <= 1)
return false;
// Check from 2 to n-1
for (int i = 2; i < n; i++)
if (n % i == 0)
return false;
return true;
}