Posts

Showing posts from June, 2017

Find the uncommon elements from common elements of an array.

In the below scenario, you are given with two array. mention the size of first array and then elements separated by space and similarly for the second array size and elements. Now need to find the uncommon elements between the common elements of array. Output: 3                                        //first array size 1                                        //first array elements 2                                                .... 3                                                 ... 4                                          //second array size 3                                           //second array elements 4                                                            .. 5                                                            .. 6                                                            .. 1$2$4$5$6                           //required output

Print the number, whose value greater the sum of digits of respective numbers

Find the even and odd number in an array,take the average of both and add them

Find the even and odd number in an array,take the average of both and add them Output 6 11 22 33 44 55 66 77

Find the maximum and minimum value in an array and multiply them

In this challenge, enter the value in one line as size of an array, and enter numbers separated by space as elements of array, find the maximum and minimum value of an array and multiply them. Output: 6 11 22 33 44 55 66 726

Find the odd index and even index in array and print the subtracted output

For this challenge we need to take size of array in one line and on other line elements separated by space. Find the odd index and add them ,find even index and add them , then subtract the smaller one from larger one. import java.io.*; import java.util.*; public class CandidateCode { public static void main(String args[] ) throws Exception { Scanner sc=new Scanner(System.in); String arraySize=sc.nextLine(); int size=Integer.parseInt(arraySize); String elements=sc.nextLine(); String [] array=new String[size]; int j=0,x=0,positive=0,negative=0; for(int i=0;i negative){ System.out.print(positive-negative); } else{ System.out.print(negative-positive); } sc.close(); } } Output: 6 11 22 33 44 55 66 33

Binary to decimal in java

import java.util.*; public class PracticeDemo { public static void main(String [] args){ Scanner sc=new Scanner(System.in); int binaryInput=sc.nextInt(); int remainder=0,i=0,value=0,decimal=0,input=binaryInput; do{ remainder=input%10; if(remainder==1){ decimal+=(int)Math.pow((int)2,(int) i); } else if(remainder==0){ i=i;} value=input/10; input=value; i++; }while(value>=10); int output=0; if(value==1){ output=decimal+(int)Math.pow((int)2, (int)i); System.out.println(output); } else{ output=decimal; System.out.println(output); } sc.close(); } } Output:011 3

Identify the subArray in an Array, such that if it is sorted then whole array will be sorted.

Identify the subArray in an Array, such that if it is sorted then whole array will be sorted. Output: 11                                                     //size of array 10 12 20 30 25 40 32 31 35 50 60  //array elements separated by space 30 25 40 32 31 35                           //sub array which needs to be sorted another sample output. 13                                                    //size of array 1 2 4 7 10 11 7 12 3 7 16 18 19      //array elements separated by space 4 7 10 11 7 12 3 7                           //sub array which needs to be sorted

Find the sum of pairs from array in java

Enter the array size as input, array elements as separated by space as input. Then the third input as integer which sum up of array elements. Input: 7 33 12 -76 11 9 7 6 20 Output: true

Find the greatest common divisor(GCD) in java

Output: 12 12 12 81 153 9

Sum of 2-D matrix in Java

Output: Enter the rows and column in a single line leaving space between between them 3 3 Add matrix element leaving space between element in single line row wise 1 2 3 4 5 6 7 8 9 Enter the rows and column in a single line leaving space between between them 3 3 Add matrix element leaving space between element in single line row wise 1 2 3 4 5 6 7 8 9 The sum of Matrix 2 4 6 8 10 12 14 16 18

Java program to find a number is Narcissistic Number or not.

Narcissistic number is a  number  that is the sum of its own digits each raised to the power of the  number  of digits. 1634 Total digit count is 4 Then you have apply Armstrong Number method on it. 1pow(4)+6power(4)+3pow(4)+4pow(4) gives 1634. hence true; public class PracticeDemo { public static int getDigitCount(int number){ int divisor=0,replacer=number,count=1; do{ divisor=replacer/10; count++; replacer=divisor; }while(divisor>10); return count; } public static boolean checkNarcissistic(int value){ boolean isNarcissistic=false; int remainder,divisible=0,replacer=value,power=getDigitCount(value),suming=0; do{ remainder=replacer%10; divisible=replacer/10; suming+=Math.pow(remainder, power); replacer=divisible; }while