2s2s2 221113 225621
2s2s2 221113 225621
2s2s2 221113 225621
5. If the reverse of the square of the number is equal to the square of the reverse
of the number, the number is an Adam number, else not.
6. Stop
Sourcecode
import java.util.Scanner;
public class AdamNumberExample
{
static int reverseDigits(int num)
{
int rev = 0;
while (num > 0)
{
rev = rev * 10 + num % 10;
num = num / 10;
}
return rev;
}
static int square(int num)
{
return (num * num);
}
static boolean isAdamNumber(int num)
{
int a = square(num);
int b = square(reverseDigits(num));
if (a == reverseDigits(b))
return true;
return false;
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number: ");
int num = sc.nextInt();
if (isAdamNumber(num))
System.out.println(num+ " is an Adam number.");
else
System.out.println(num+ " not an Adam number.");
}
}
Output
Enter the number :32
Is an adam number
___________________________________________________________________
Sourcecode
import java.util.Scanner;
class ArmstrongNum
num = sc.nextInt();
originalNum = num;
while (num!= 0)
num /= 10;
if(cubeSum == originalNum)
}
}
Output
Enter the number: 153
ALGORITHM
1 Traverse the array from start to end.
2 For every index increment the element by array[array[index] ] %
n. To get the ith element find the modulo with n, i.e
array[index]%n.
3 Again Traverse the array from start to end
4 Print the ith element after dividing the ith element by n, i.e.
array[i]/n.
5 Stop
Sourcecode
import java.util.*;
String wrd,newwrd;
Rearrange(){}
void readword()
System.out.println("Enter a word" );
wrd=x.next();
wrd=wrd.toUpperCase();
void freq_vow_con()
int s=0,s1=0;
char ch;
for(int i=0;i<wrd.length();i++) {
ch=wrd.charAt(i);
if("AEIOU".indexOf(ch)!=-1)
s++;
s1= wrd.length()-s;
void arrange()
char ch;
String p="",q="";
for(int i=0;i<wrd.length();i++) {
ch=wrd.charAt(i);
if("AEIOU".indexOf(ch)!=-1)
p +=ch;
else
q +=ch;
newwrd= p+q;
void display()
obj.readword();
obj.freq_vow_con();
obj.arrange();
obj.display();
}
}
Output
ORIGINAL becomes OIIARGNL
ALGORITHM
1 Declare and define the function get1() to get the salary details.
Sourcecode
class A {
class B extends A{
class C extends A {
{
System.out.println("method of Class C");
class D extends A{
class InheritncExm{
obj1.methodA();
obj2.methodA();
obj3.methodA();
ALGORITHM
1 Read or initialize a number N.
B. Define two arrays one for storing the prime numbers and the other for
calculating the prime number.
C. Find all prime numbers till the entered number using a for loop and store
it in an array.
D. In the second array, store only odd prime numbers using if statement.
6 By using the for loop, store the sum of two odd prime numbers in a variable
(sum).
7 Using the if statement, compare the sum with the original number N. If the
sum is equal to the original number, the given number N is Goldbach
Number, else not.
Sourcecode
import java.util.Scanner;
int c = 0;
if (num % i == 0) {
c++;
return c == 2;
int n = in.nextInt();
return;
if (n % 2 != 0) {
return;
int a = 3;
int b = 0;
while (a <= n / 2) {
b = n - a;
a += 2;
} Output
ALGORITHM
1 We first take a number.
3 We add the factorial of each digit and store it into another variable.
4 If the sum of the factorial of each digit is the same as the original number, the
number is a Krishnamurthy number
Sourcecode
import java.util.Scanner;
String s = Integer.toString(number);
int l = s.length();
while(temp>0)
a = temp % 10;
l--;
if(sum == number)
else
}
}
Output
ALGORITHM
6 STEP 1: START
9 STEP 4: END
Kaprekar(int n)
7. STEP 1: START
8. STEP 2: if(n==1) RETURN true
12.STEP 6: count_digits++
13.STEP 7: sq_n/=10
Sourcecode
public class Kaprekar_Number {
1 static boolean kaprekar(int n)
2 {
3 if (n == 1)
4 return true;
5 int sq_n = n * n;
6 int count_digits = 0;
7 while (sq_n != 0)
8 {
9 count_digits++;
10 sq_n /= 10;
11 }
12 sq_n = n*n;
13 for (int r_digits=1; r_digits<count_digits; r_digits++)
14 {
15 int eq_parts = (int) Math.pow(10, r_digits);
16 if (eq_parts == n)
17 continue;
20 return true;
21 }
22 return false;
23 }
30 }
Output
8. Java Program to Print Diamond Pattern
Sourcecode
import java.util.Scanner;
System.out.println("Enter N : ");
int n=sc.nextInt();
FOR(int i=1;i<=n;i++)
FOR(int j=1;j<=n-i;j++)
System.out.print(" ");
FOR(int j=1;j<=i*2-1;j++)
System.out.print(c);
System.out.println();
FOR(int i=n-1;i>0;i--)
FOR(int j=1;j<=n-i;j++)
System.out.print(" ");
FOR(int j=1;j<=i*2-1;j++)
System.out.print(c);
System.out.println();
}
Output
Enter N : $ javac Diamond.java
$ java Diamond
***
*****
*******
*********
*******
*****
***
______________________________________________________________________________________________
Sourcecode
10 public class Transpose
11 {
14 int a[][] = {
15 {1, 2, 3},
16 {4, 5, 6},
17 {7, 8, 9}
18 };
19 rows = a.length;
20 cols = a[0].length;
21 int t[][] = new i
25 {
26 t[i][j] = a[j][i];
27 }
28 }
29
30 System.out.println("Transpose of given matrix: ");
35 System.out.println();
36 }
37 }
38 }
Output
Result matrix is
1234
1234
1234
10. Xylem and Phloem Number Java Program
ALGORITHM
• Read or initialize a number N.
• Sum up the extreme digits and store the sum in a variable (extreme_sum).
Sourcecode
1 import java.io.*;
14 Yh
16 else
17 mean_sum = mean_sum + n % 10;
18 n = n / 10;
19 }
20 825122
21 System.out.println("The sum of mean digits: " + mean_7. );
22 if(extreme_sum == mean_sum)
24 else
25 System.out.println(num + " is a phloem number.");
26 }
Output
Enter a number: 825122
The sum of extreme digits: 10
The sum of mean digits: 10
825122 is a xylem number.
11.WRITE A JAVA PROGRAM TO CHECK
WHETHER A NUMBER IS STRONTIO
NUMBER OR NOT
Strontio numbers are those four digits numbers when multiplied by 2 give the same
digit at the hundreds and tens place.
ALGORITHM
1. Read or initialize a number N.
3. Find remainder by dividing the resultant (from step 2) by 1000. Divide the
resultant (from step 2) by 1000. It removes the first digit from the resultant.
4. Divide the resultant (from step 3) by 10. It removes the last digit from the
resultant and gives a two-digit number.
5. Again, divide the two-digit number (from step 4) by 10, it gives the quotient.
By using the modulo operator find the remainder.
6. Compare both remainder and quotient. If they are equal, the given number (N)
is strontio, else not.
Sourcecode
7. import java.util.*;
8. public class StrontioNumberExample1
9. {
10. public static void main(String args[])
11. {
12. Scanner sc=new Scanner(System.in);
16. num=(num*2%1000)/10;
17. if(num%10==num/10)
19. else
20. System.out.println(n+ " is not a strontio number.");
21. }
22. }
Output
12.WRITE A JAVA PROGRAM TO
CHECK WHETHER NUMBER IS
NELSON NUMBER OR NOT.
In cricket, the number 111 is sometimes called “a Nelson” after Admiral
Nelson, who allegedly only had “One Eye, One Arm, One Leg” near the end of
his life.
ALGORITHM
1.Start
4.Add all the n-digits. It gives the next term of the series.
5.Again, add the last n-terms of the series to find the next term.
6.Repeat step 4 until we get the term the same as the number we have taken.
7.Stop
Sourcecode
import java.util.Scanner;
System.out.println("Enter a number");
int n=in.nextInt();
System.out.println("Nelson Number");
} else {
Output
Enteranumber
111
Nelson Number
13 Java Program to find the sum of each row
and each column of a matrix
ALGORITHM
39 STEP 1: START
Sourcecode
55 public class SumofRowColumn
56 {
61 cols = a[0].length;
62 for(int i = 0; i < rows; i++){
63 sumRow = 0;
64 for(int j = 0; j < cols; j++){
73 }
74 System.out.println("Sum of " + (i+1) +" column: " + sumCol);
75 }
76 }
77 }
Output
perform task
perform task
perform task
Sourcecode
import java.util.Scanner;
int a,b,
int choice;
while(true)
System.out.println("Press 1 for Addition");
choice = scanner.nextInt();
switch (choice) {
case 1:
a = scanner.nextInt();
b = scanner.nextInt();
c = a + b;
break;
case 2:
a = scanner.nextInt();
b = scanner.nextInt();
c = a - b;
break;
case 3:
a = scanner.nextInt();
b = scanner.nextInt();
c = a * b;
break;
case 4:
a = scanner.nextInt();
b = scanner.nextInt();
c = a / b;
case 5:
System.exit(0);
default:
}
Output
15. Java Program to find Reverse of the
string
ALGORITHM
78 STEP 1: START
83 STEP 6: i = i - 1
86 STEP 9: END
Sourcecode
87 public class Reverse
88 {
93
94 //Iterate through the string from last and add each character to variable reversedStr
97 }
98
102 }
16.Java program for banking management
system
ALGORITHM
1.Start
2.Display All
3.Search By Account
4.Deposit
5.Withdrawal
6.Exit
Sourcecode
import java.util.Scanner;
class Bank {
void openAccount() {
accno = KB.next();
balance = KB.nextLong();
void showAccount() {
void deposit() {
long amt;
amt = KB.nextLong();
void withdrawal() {
long amt;
amt = KB.nextLong();
} else {
if (accno.equals(acn)) {
showAccount();
return (true);
return (false);
int n = KB.nextInt();
C[i].openAccount();
int ch;
do {
switch (ch) {
case 1:
break;
case 2:
found = C[i].search(acn);
if (found) {
break;
if (!found) {
break;
case 3:
acn = KB.next();
found = false;
found = C[i].search(acn);
if (found) {
C[i].deposit();
break;
if (!found) {
System.out.println("Search Failed..Account Not Exist..");
break;
case 4:
acn = KB.next();
found = false;
found = C[i].search(acn);
if (found) {
C[i].withdrawal();
break;
if (!found) {
break;
case 5:
System.out.println("Good Bye..");
break;
Output
How Many Customer U Want to Input : 2
Enter Account No: 101
Main Menu
1.Display All
2.Search By Account
3.Deposit
4.Withdrawal
5.Exit
Ur Choice :
101,Chintu,25000
102,Alexander,30000
1
17.Java program to find if the given
number is a leap year?
ALGORITHM
1. Take integer variable year
3. Check if the year is divisible by 4 but not 100, DISPLAY "leap year"
Sourcecode
import java.util.Scanner;
public class LeapYear {
public static void main(String[] args){
int year;
System.out.println("Enter an Year :: ");
Scanner sc = new Scanner(System.in);
year = sc.nextInt();
Output
Enter an Year ::
2020
Specified year is a leap year
vCount = vCount + 1.
STEP 8: IF any character excepting vowels lies BETWEEN a and z then
cCount = cCount =+1.
STEP 9: i = i + 1
//Declare a string
str = str.toLowerCase();
vCount++;
cCount++;
}
Output
Number of vowels: 10
Number of consonants: 17
ALGORITHM
STEP 1: START
STEP 4: END
Sourcecode
103 public class Kaprekar_Number {
104 static boolean kaprekar(int n)
105 {
106 if (n == 1)
111 {
112 count_digits++;
117 {
118 int eq_parts = (int) Math.pow(10, r_digits);
119 if (eq_parts == n)
120 continue;
133 }
Output
8 10 45 55 99
Step3: if(arr[j]>arr[j+1]
Step4: swap(arr[j],arr[j+1])
Step5: End
Sourcecode
134 public class BubbleSortExample {
135 static void bubbleSort(int[] arr) {
136 int n = arr.length;
137 int temp = 0;
146
147 }
148 }
149
150 }
151 public static void main(String[] args) {
158 System.out.println();
159
166
167 }
168
169
Output
Bibliography
I have taker help from the following sites
Sites:
1. Google.com
2. YouTube.com
3.JAVA school tutorial org
Books:
1. Sumita Arora dass 12th computer book
People':
1. Our computer teacher Indrajeet sir
2. My parents
3. My helpful friends
Thank you