"I am delighted once again to pen the welcome note to the Tosh!Yas Technologies ."
Call +91 74 88 34 7779  Email : anishsingh@live.com
Write a Program in Java to input a number and check whether it is a Disarium Number or not.
Note: A number will be called DISARIUM if sum of its digits powered with their respective position is equal to the original number.
For example 135 is a DISARIUM
(Workings 1^{1}+3^{2}+5^{3} = 135, some other DISARIUM are 89, 175, 518 etc)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

/** * The class Disarium inputs a number and checks whether * it is a Disarium number or not * @author : www.anishsir.in * @Program Type : BlueJ Program  Java */ import java.io.*; class Disarium { public static void main(String[] args) throws IOException { BufferedReader br= new BufferedReader ( new InputStreamReader(System.in)); System.out.print( "Enter a number : " ); int n = Integer.parseInt(br.readLine()); int copy = n, d = 0 , sum = 0 ; String s = Integer.toString(n); //converting the number into a String int len = s.length(); //finding the length of the number i.e. no.of digits while (copy> 0 ) { d = copy % 10 ; //extracting the last digit sum = sum + ( int )Math.pow(d,len); len; copy = copy / 10 ; } if (sum == n) System.out.println(n+ " is a Disarium Number." ); else System.out.println(n+ " is not a Disarium Number." ); } } 
Enter a Number : 135
135 is a Disarium Number.
Enter a Number : 219
219 is not a Disarium Number.
Enter a Number : 89
89 is a Disarium Number.
Write a program to input a word from the user and remove the duplicate characters present in it.
Example:
INPUT – abcabcabc
OUTPUT – abc
INPUT – javaforschool
OUTPUT – javforschl
INPUT – Mississippi
OUTPUT – Misp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

/** * The class RemoveDupChar inputs a word and removes duplicate characters * @author : www.anishsir.in * @Program Type : BlueJ Program  Java */ import java.io.*; class RemoveDupChar { public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader( new InputStreamReader(System.in)); System.out.print( "Enter any word : " ); String s = br.readLine(); int l = s.length(); char ch; String ans= "" ; for ( int i= 0 ; i<l; i++) { ch = s.charAt(i); if (ch!= ' ' ) ans = ans + ch; s = s.replace(ch, ' ' ); //Replacing all occurrence of the current character by a space } System.out.println( "Word after removing duplicate characters : " + ans); } } 
Example 1:
Enter any word : Mississippi
Word after removing duplicate characters : Misp
Example 2:
Enter any word : Attitude
Word after removing duplicate characters : Atiude
Write a Program in Java to input 2 numbers and find their Greatest Common Divisor (GCD).
Note: If the 2 numbers are 54 and 24, then the divisors (factors) of 54 are: 1, 2, 3, 6, 9, 18, 27, 54.
Similarly the divisors (factors) of 24 are: 1, 2, 3, 4, 6, 8, 12, 24.
The numbers that these two lists share in common are the common divisors (factors) of 54 and 24: 1, 2, 3, 6.
The greatest (highest) of these is 6. That is the greatest common divisor or the highest common factor of 54 and 24.
Calculating HCF / GCD by Prime Factorisation Method is long and more timeconsuming, and due to these disadvantages new method was evolved by Mathematician namely, Successive Division Method
Under Successive Division Method, HCF / GCD = The Last Divisor of the given numbers .
Following example can guide you How to calculate HCF / GCD by Successive Division Method ?
Example : By using Successive Division Method, find the GCD of 24 & 18 ?
Answer : Steps and the way of finding GCD by Successive Division Method is as :
Step 1 = Divide the larger number 24 by the smaller number 18. And this division will give remainder 6.
Step 2 = Now, divide 18 (divisor of step 1) with 6 (remainder of step 1)
Step 3 = Division in Step 2 give us remainder 0 (Zero). And The Last Divisor is the GCD of 24 & 18.
Hence, GCD = 6
18  24  1 18 ______ 6  18  3 18 ______ 0 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

/** * The class Gcd inputs two numbers and finds their Gcd * @author : www.anishsir.in * @Program Type : BlueJ Program  Java */ import java.util.*; class Gcd { public static void main(String args[]) throws Exception { Scanner sc = new Scanner(System.in); System.out.print( "Enter the First no : " ); int n1=sc.nextInt(); System.out.print( "Enter the Second no : " ); int n2=sc.nextInt(); int r; while (n2 != 0 ) { r = n1 % n2; n1 = n2; n2 = r; } System.out.print( "GCD = " +n1); } } 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

/** * The class Gcd inputs two numbers and finds their Gcd * @author : www.anishsir.in * @Program Type : BlueJ Program  Java */ import java.util.*; class Gcd { public static void main(String args[]) throws Exception { Scanner sc = new Scanner(System.in); System.out.print( "Enter the First no : " ); int n1=sc.nextInt(); System.out.print( "Enter the Second no : " ); int n2=sc.nextInt(); while (n1 != n2) { if (n1 > n2) n1 = n1n2; else n2 = n2n1; } System.out.print( "GCD = " +n1); } } 
Enter the First no : 54
Enter the Second no : 24
GCD = 6
Write a Program in Java to input a number and check whether it is a Harshad Number or Niven Number or not..
Harshad Number : In recreational mathematics, a Harshad number (or Niven number), is an integer (in base 10) that is divisible by the sum of its digits.
Let’s understand the concept of Harshad Number through the following example:
The first few Harshad numbers in base 10 are:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 18, 20, 21, 24, 27, 30, 36, 40, 42, 45, 48, 50, 54, 60, 63, 70, 72, 80, 81, 84, 90, 100, 102, 108, 110, 111, 112, 114, 117, 120, 126, 132, 133, 135, 140, 144, 150, 152, 153, 156, 162, 171, 180, 190, 192, 195, 198, 200 etc.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

/** * The class HarshadNumber inputs a number and checks if it a Harshad Number or not * @author : www.anishsir.in * @Program Type : BlueJ Program  Java */ import java.util.*; class HarshadNumber { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.print( "Enter a number : " ); int n = sc.nextInt(); int c = n, d, sum = 0 ; //finding sum of digits while (c> 0 ) { d = c% 10 ; sum = sum + d; c = c/ 10 ; } if (n%sum == 0 ) System.out.println(n+ " is a Harshad Number." ); else System.out.println(n+ " is not a Harshad Number." ); } } 
Enter a number : 195 195 is a Harshad Number. Enter a number : 194 194 is not a Harshad Number. Enter a number : 190 190 is a Harshad Number. Enter a number : 111 111 is a Harshad Number. 
Write a Program in Java to input a number and check whether it is a Pronic Number or Heteromecic Number or not.
Pronic Number : A pronic number, oblong number, rectangular number or heteromecic number, is a number which is the product of two consecutive integers, that is, n (n + 1).
The first few pronic numbers are:
0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420, 462 … etc.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

/** * The class HarshadNumber inputs a number and checks if it a Pronic Number or not * @author : www.anishsir.in * @Program Type : BlueJ Program  Java */ import java.util.*; class PronicNumber { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.print( "Enter a number : " ); int n = sc.nextInt(); int flag = 0 ; for ( int i= 0 ; i<n; i++) { if (i*(i+ 1 ) == n) { flag = 1 ; break ; } } if (flag == 1 ) System.out.println(n+ " is a Pronic Number." ); else System.out.println(n+ " is not a Pronic Number." ); } } 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

/** * The class HarshadNumber inputs a number and checks if it a Pronic Number or not * @author : www.anishsir.in * @Program Type : BlueJ Program  Java */ import java.util.*; class PronicNumber { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.print( "Enter a number : " ); int n = sc.nextInt(); int k = ( int )(Math.sqrt(n)); if (k*(k+ 1 )==n) System.out.println(n+ " is a Pronic Number." ); else System.out.println(n+ " is not a Pronic Number." ); } } 
Enter a number : 110 110 is a Pronic Number. Enter a number : 73 73 is not a Pronic Number. Enter a number : 342 342 is a Pronic Number. Enter a number : 15 15 is not a Pronic Number. 
What is a Data Structure?
A data structure is a way of organizing the data so that the data can be used efficiently. Different kinds of data structures are suited to different kinds of applications, and some are highly specialized to specific tasks. For example, Btrees are particularly wellsuited for implementation of databases, while compiler implementations usually use hash tables to look up identifiers.
What are linear and non linear data Structures?
What are the various operations that can be performed on different Data Structures?
How is an Array different from Linked List?
What is Stack and where it can be used?
Stack is a linear data structure which the order LIFO(Last In First Out) or FILO(First In Last Out) for accessing elements. Basic operations of stack are : Push, Pop , Peek
Applications of Stack:
What is a Queue, how it is different from stack and how is it implemented?
Queue is a linear structure which follows the order is First In First Out (FIFO) to access elements. Mainly the following are basic operations on queue: Enqueue, Dequeue, Front, Rear
The difference between stacks and queues is in removing. In a stack we remove the item the most recently added; in a queue, we remove the item the least recently added. Both Queues and Stacks can be implemented using Arrays and Linked Lists.
What are Infix, prefix, Postfix notations?
A * ( B + C ) / D
A B C + * D/
/ * A + B C D
What is a Linked List and What are its types?
A linked list is a linear data structure (like arrays) where each element is a separate object. Each element (that is node) of a list is comprising of two items – the data and a reference to the next node.Types of Linked List :
Which data structures are used for BFS and DFS of a graph?
Can doubly linked be implemented using a single pointer variable in every node?
Doubly linked list can be implemented using a single pointer.
How to implement a stack using queue?
A stack can be implemented using two queues. Let stack to be implemented be ‘s’ and queues used to implement be ‘q1’ and ‘q2’. Stack ‘s’ can be implemented in two ways:
How to implement a queue using stack?
A queue can be implemented using two stacks. Let queue to be implemented be q and stacks used to implement q be stack1 and stack2. q can be implemented in two ways:
Which Data Structure Should be used for implementiong LRU cache?
We use two data structures to implement an LRU Cache.
How to check if a given Binary Tree is BST or not?
If inorder traversal of a binary tree is sorted, then the binary tree is BST. The idea is to simply do inorder traversal and while traversing keep track of previous key value. If current key value is greater, then continue, else return false.
To delete a tree we must traverse all the nodes of the tree and delete them one by one. So which traversal we should use – Inorder or Preorder or Postorder. Answer is simple – Postorder, because before deleting the parent node we should delete its children nodes first
We can delete tree with other traversals also with extra space complexity but why should we go for other traversals if we have Postorder available which does the work without storing anything in same time complexity.
For the following tree nodes are deleted in order – 4, 5, 2, 3, 1
#include<stdio.h>
#include<stdlib.h>
/* A binary tree node has data, pointer to left child
and a pointer to right child */
struct
node
{