0% found this document useful (0 votes)
6 views

Kaveesha Holdiay Assignment

Macro

Uploaded by

pabayapabaya731
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Kaveesha Holdiay Assignment

Macro

Uploaded by

pabayapabaya731
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 45

Progressive English School,

Sharjah

Department of science
CERTIFIED THAT THIS IS THE BONAFIDE RECORD OF
WORK
DONE IN PROJECT ACTIVITIES IN COMPUTER
APPLICATION

OF________________________________
REG NO.____________________________ GRADE 10 ___
DURING THE YEAR 2023 - 2024

TEACHER IN CHARGE
1._________________________________ ____________
INDEX
No. Program Pag
e
1. Program to check whether a number is ‘Neon’ or not 4

2. Program to check whether a number is Automorphic number or not 6

3. Program to check if a number is Armstrong number or not 8

4. Program to print the sum of series S=1+(1+2)+(1+2+3)+…….. (1+2+3…..+n) 10


(read the value of n from the user)
5. Write a menu driven program to find the area of equilateral triangle, Isosceles 12
triangle and a scalene triangle as per user’s choice.

6. Write a program in Java to store 15 numbers (even and odd numbers) in a 14


single dimensional Array (SDA). Calculate and display the sum of all even
numbers and all odd numbers separately.
7. Program to find the second smallest element from an array. 16

8. Write a program to store 10 numbers in SDA. Now display only those numbers 18
that are perfect square.
9. Program to search an element from an array using Linear search technique. 20

10. Program to search an element from an array using Binary search technique. 22

11. Program to accept a word and check whether the word is palindrome or not 24

12. Program to sort the states according to their names using Bubble sort 26
technique. (Descending order)
13 Write a Program to display piglatin form of word. 28

14. Write a program to accept a word and convert it into a lowercase. if it is 30


uppercase display the new word by replacing only the vowels with the letter
following it

15. Write a program in Java to enter a string/sentence and display the length of 32
the longest word present in the string.
16. Write a program to input 10 names in an SDA. Arrange these names in 34
ascending order of letters, using selection sort technique.
17. .Write a class with the name Area using function overloading that compute the 36
area of following
(a)Area of circle =22/7*r*r
(b)Area of square=side*side
(c) Area of rectangle=length*breadth

18. Write a Program in Java to store the numbers in a 4*4 matrix in DDA. find the 38
sum of the numbers of each row and sum of the numbers of each column of
the matrix by using an input statement.

19. Write a Program in Java to store the numbers in a 4*4 matrix in DDA. find the 40
sum of the numbers of left diagonal and sum of the numbers of right diagonal
of the matrix by using an input statement.
20. Design a class to overload a function compare () as follows: 42
(i) void compare (int, int): to compare two integer values and print the greater
of the two integers.
(ii) void compare (char, char): to compare numeric value of two character and
1.Program to check whether a number is ‘Neon Number’ or not.

import java.util.*;
public class Neon
{
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
int n,sum=0,p,d;
System.out.println("Enter the number: ");
n=in.nextInt();
p=n*n;
do
{
d=p%10;
sum=sum+d;
p=p/10;
}
while (p!=0);
if(sum==n)
System.out.println("Neon number.");
else
System.out.println("Not a Neon number.");
}
}

OUTPUT
Enter the number:
9
Neon number.
Enter the number:
12
Not a Neon number.

VARIABLE DESCRIPTION
SL Variables Data Type Description
no
.
1 n Int To Store the entered number
2 Sum Int To store the sum
3 p Int To store the number after squaring

4 d Int The last digit of p (used to sum the


digits).

2.Program to check whether a number is Automorphic number or not

import java.util.*;
public class Automorphic
{
public static void main (int num)
{
int p,f=0;
p=num*num;
do
{
if(num%10!=p%10)
{
f=1;
break;
}
else
{
num=num/10;
p=p/10;
}
}
while(num>0);
if(f==0)
System.out.println("Automorphic number");
else
System.out.println("Not an Automorphic number");
}
}

OUTPUT
Enter the number
25
Automorphic number
Enter the number
20
Not an Automorphic number

VARIABLE DESCRIPTION
SL Variables Data Type Description
no
.
1 `num` Int The input number to be checked if
it's an Automorphic number
2 p Int The square of the input number
(`num * num`).
3 f Int A flag variable used to indicate
whether the number is
Automorphic

3.Program to check if a number is Armstrong number or not.

public class Armstrong


{
public static void main(int n)
{
int a,num,s=0;
num=n;
while(n>0)
{
a=n%10;
s=s+a*a*a;
n=n/10;
}
if(num==s)
System.out.println("The number " +num +" is an Armstrong Number");
else
System.out.println("The number " +num +" is not an Armstrong Number");
}
}

OUTPUT
Enters the value 153 during execution:
The number 153 is an Armstrong Number
Enters the value 123 during execution:
The number 123 is not an Armstrong Number

VARIABLE DESCRIPTION

SL Variables Data Type Description


no
.
1 n Int The input number to be checked if
it's an Armstrong number.
2 a Int The last digit of n extracted during
each iteration of the loop
3 num Int A copy of the original input
number (n) to compare with the
sum of cubes.
4 s Int The sum of the cubes of the digits
of the number

4.Program to print the sum of series S=1+(1+2)+(1+2+3)+…….. (1+2+3…..+n) (read the value
of n from the user)

import java.util.*;
public class Series
{
public static void main(String args[])
{
Scanner in = new Scanner (System.in);
long n,i,j;
System.out.println("Enter n");
n=in.nextLong();
long sum=0;
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
sum=sum+j;
}
System.out.println("The sum of the series is "+sum);
}
}

OUTPUT
Enter n
5
The sum of the series is 35
Enter n
100
The sum of the series is 171700

VARIABLE DESCRIPTION
SL Variables Data Type Description
no
.
1 n long The input number that determines
the length of the series.
2 i long Loop control variable for the outer
loop, iterating from `1` to `n`.
3 j long Loop control variable for the inner
loop, iterating from `1` to `i`.
4 sum long Accumulates the sum of the series

5.Write a menu driven program to find the area of equilateral triangle, Isosceles triangle and a
scalene triangle as per user’s choice.

public class Triangle


{
public static void main(String args[])
{
Scanner in= new Scanner(System.in);
int c,s,a,b,m,n,p;
double k, area=0;
System.out.println("1. Area of an Equilateral Triangle");
System.out.println("2. Area of an Isoceles Triangle");
System.out.println("3. Area of a Scalene Triangle");
System.out.println("Enter your choice");
c=in.nextInt();
switch(c)
{
case 1:
System.out.println("Enter side of an Equilateral Triangle");
s=in.nextInt();
area= (Math.sqrt(3)*s*s)/4.0;
System.out.println("Area="+area);
break;
case 2:
System.out.println("Enter side and base of Isoceles Triangle");
a=in.nextInt();
b=in.nextInt();
area=b*(Math.sqrt(4*a*a-b*b))/4.0;
System.out.println("Area="+area);
break;
case 3:
System.out.println("Enter sides of Scalene Triangle");
m=in.nextInt();
n=in.nextInt();
p=in.nextInt();
k=(m+n+p)/2.0;
area=Math.sqrt(k*(k-m)*(k-n)*(k-p));
System.out.println("Area="+area);
break;
default:
System.out.println("Wrong Choice!!");
}
}
}

OUTPUT
Input:
1
Enter side of an Equilateral Triangle
6
Output:
Area=15.588457268119896

VARIABLE DESCRIPTION
Variable Data Description
Name Type
c int Stores the user's choice for the type of triangle.
s int Side length of the equilateral triangle.
a int Side length of the isosceles triangle.
b int Base length of the isosceles triangle.
m int First side length of the scalene triangle.
n int Second side length of the scalene triangle.
p int Third side length of the scalene triangle.
k double Semi-perimeter of the scalene triangle, calculated as (m + n +
p) / 2.0.
area double Area of the triangle based on the selected type.

6.Write a program in Java to store 15 numbers (even and odd numbers) in a single dimensional
Array (SDA). Calculate and display the sum of all even numbers and all odd numbers
separately.

import java.util.*;
public class Even_Odd
{
public static void main(String args[])
{
Scanner in = new Scanner (System.in);
int i,es=0,os=0;
int m[]=new int[15];
System.out.println("Enter the numbers in the cell");
for(i=0;i<15;i++)
{
m[i]=in.nextInt();
}
for(i=0;i<15;i++)
{
if(m[i]%2==0)
es=es+m[i];
else
os=os+m[i];
}
System.out.println("The sum of the even numbers "+es);
System.out.println("The sum of the odd numbers "+os);
}
}
OUTPUT
Input:
Enter the numbers in the cell 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Output:
The sum of the even numbers 56
The sum of the odd numbers 64

VARIABLE DESCRIPTION

SL Variables Data Type Description


no.
1 Scanner Object to take input from the user.
in
2 Int Loop control variable used to
i
traverse through the array.
3 es Int Stores the sum of even numbers
from the array.
4 os Int Stores the sum of odd numbers
from the array.
5 m[ ] Int[ ] Array of size 15 that stores the
numbers entered by the user.
7.Program to find the second smallest element from an array.

import java.util.*;
public class SecondSmall{
public static void main(String args[]){
Scanner in = new Scanner(System.in);
int i,min,secondmin;
int a[] = new int[10];
for(i=0;i<10;i++){
System.out.println("Enter the value of Cell: "+(i+1));
a[i] = in.nextInt();
}
min= a[0];
for(i=0;i<10;i++){
if(a[i]<min)
min=a[i];
}
System.out.println("Smallest Number: "+min);
secondmin = a[9];
for(i=0;i<10;i++){
if(a[i]<secondmin && a[i]!=min)
secondmin = a[i];
}
System.out.println("Second Smallest Number: "+secondmin);
}
}
OUTPUT

Input:
Enter the value of Cell: 1
45
Enter the value of Cell: 2
23
Enter the value of Cell: 3
67
Enter the value of Cell: 4
12
Enter the value of Cell: 5
98
Enter the value of Cell: 6
34
Enter the value of Cell: 7
56
Enter the value of Cell: 8
12
Enter the value of Cell: 9
90
Enter the value of Cell: 10
29
Output:
Smallest Number: 12
Second Smallest Number: 23

VARIABLE DESCRIPTION

SL no. Variable Name Data Type Description


1. I Int [] Store the elements of
array.
2. Min int Store the min no.
3. Secondmin int Store 2nd min no.
8.Write a program to store 10 numbers in SDA. Now display only those numbers that are perfect
square.

import java.util.*;
public class Perfect_sq
{
public static void main (String args[])
{
Scanner in=new Scanner(System.in);
int i,k=0;
int m[]=new int [10];
System.out.println("Enter the numbers in the cell");
for(i=0;i<10;i++)
{
m[i]=in.nextInt();
}
System.out.println("The numbers in perfect square are:");
for(i=0;i<10;i++)
{
k=(int)Math.sqrt(m[i]);
if(k*k==m[i])
{
System.out.println(m[i]);
}
}
}
}
OUTPUT
Input:
Enter the numbers in the cell
16 23 25 30 36 40 49 50 64 81
Output:
The numbers in perfect square are:
16
25
36
49
64
81

VARIABLE DESCRIPTION

SL no. Variable Name Data Type Description


1. I int Loop control variable
for iterating through the
array.
2. K int Stores the integer
square root of each
number in the array.
3. m[] int[] Array to store 10 input
numbers from the user.
9. Program to search an element from an array using Linear search technique.

import java.util.*;
public class LH_search
{
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
int i, k = 0, ns;
int m[] = new int[10];

System.out.println("Enter the values in an Array");


for(i = 0; i < 10; i++)
{
m[i] = in.nextInt();
}

System.out.println("The number to be searched");


ns = in.nextInt();

for(i = 0; i < 10; i++)


{
if(m[i] == ns)
{
k = 1;
break; // Stop the loop once the number is found
}
}

if(k == 1)
System.out.println("The number is present");
else
System.out.println("The number is not present");
}
}
OUTPUT
Input:
Enter the values in an Array
12 45 23 56 78 89 90 34 67 12
The number to be searched
56
Output:
The number is present.

VARIABLE DESCRIPTION

SL no. Variable Name Data Type Description


1 I int Loop control variable
for iterating through
the array.
2 K int Flag variable
indicating if the
number is found (1 if
found).
3 Ns int The number to be
searched in the
array.
4 m[] int[] Array of 10 integers
input by the user.
10. Program to search an element from an array using Binary search technique.

import java.util.*;
public class B_search
{
public static void main (String args[])
{
Scanner in = new Scanner(System.in);
int i,k=0,p=0,lb=0,ub=9,ns;
int m[]=new int[10];
System.out.print("Enter the value in Ascending order");
for(i=0;i<10;i++)
{
m[i]=in.nextInt();
}
System.out.println("Enter the number to be searched");
ns=in.nextInt();
while(lb<=ub)
{
p=(lb+ub)/2;
if(m[p]<ns)
lb=p+1;
if(m[p]>ns)
ub=p-1;
if(m[p]==ns)
{
k=1;
break;
}
}
if(k==1)
System.out.println("The number is present");
else
System.out.println("The number is not present");
}
}
OUTPUT
Input:
Enter the values in Ascending order:
10 20 30 40 50 60 70 80 90 100
Enter the number to be searched:
50
Output:
The number is present

VARIABLE DESCRIPTION

SL Variable Name Data Type Description


no.
1 I int Loop control
variable for iterating
through the array.
2 K int Flag variable
indicating if the
number is found (1 if
found).
3 P int Stores the middle
element during the
binary search.
4 Lb int Lower bound index
for binary search.
11.Program to accept a word and check whether the word is palindrome or not.

import java.util.*;
public class Palindrome
{
public static void main(String word)
{
int i,p;
String word1="";
char ch;
p=word.length();
for(i=p-1;i>=0;i--)
{
ch=word.charAt(i);
word1=word1+ch;
}
if(word1.equals(word))
System.out.println("Palindrome");
else
System.out.println("Not a Palindrome");
}
}
OUTPUT
Input:
Enter a word:
Radar
Output:
Palindrome

VARIABLE DESCRIPTION

SL no. Variable Name Data Type Description


1 I int Loop control variable
to traverse the string.
2 P int Stores the length of
the input string.
3 Ch char Stores individual
characters from the
string for comparison.
12.Program to sort the states according to their names using Bubble sort technique.
(Descending order)

import java.util.*;
public class Bubble_Sort
{
public static void main(String args[])
{
Scanner in = new Scanner (System.in);
String ch[]=new String [10];
String t="";
int i,j;
System.out.println("Enter the array elements");
for(i=0;i<10;i++)
ch[i]=in.next();
for(i=0;i<9;i++)
{
for(j=0;j<(9-i);j++)
{
if(ch[j].compareTo(ch[j+1])<0)
{
t=ch[j];
ch[j]=ch[j+1];
ch[j+1]=t;
}
}
}
System.out.println("The names in descending order are:");
for(i=0;i<10;i++)
System.out.println(ch[i]);
}
}
OUTPUT
Input:
Enter the array elements
apple
orange
banana
grape
kiwi
mango
pineapple
watermelon
pear
plum
Input:
The names in descending order are:
watermelon
pineapple
plum
pear
mango
kiwi
grape
banana
orange
apple

VARIABLE DESCRIPTION

SL no. Variable Name Data Type Description


1 I int Loop control variable
to traverse the array.
2 J int Loop control variable
for comparing
adjacent elements.
3 T String Temporary variable
for swapping two
elements.
4 ch[] String[] Array of 10 strings to
be sorted.
13.Write a Program to display piglatin form of word.

public class Piglatin


{
public static void main (String str)
{
int x,y;
String str1,str2;
char b;b=0;
x=str.length();
System.out.println("Enter the string ");
for(y=0;y<x;y++)
{
b=str.charAt(y);
if(b=='a'||b=='e'||b=='i'||b=='o'||b=='u'||b=='A'||b=='E'||b=='I'||b=='O'||b=='U')
break;
}
str1=str.substring(y,x);
str2=str.substring(0,y);
System.out.println(str1+str2+"ay");
}
}
OUTPUT
Enter the string
example
exampleay

VARIABLE DESCRIPTION

S Variable Name Data Type Description


1 X int Stores the length of
the input string.
2 Y int Loop control variable
to traverse the string.
3 B char Stores individual
characters from the
string.
14.Write a program to accept a word and convert it into a lowercase. if it is uppercase display
the new word by replacing only the vowels with the letter following it.

import java.util.*;
public class Chvowels
{
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
int i,p;
String st,st1="";
char chr;
System.out.println("Enter the String");
st=in.next().toLowerCase();
p=st.length();
for(i=0;i<p;i++)
{
chr=st.charAt(i);
if(chr=='a'||chr=='e'||chr=='i'||chr=='o'||chr=='u')
st1=st1+(char)(chr+1);
else
st1=st1+chr;
}
System.out.println("The Interchanged word: "+st1);
}
}
OUTPUT
Enter the String
hello
The Interchanged word: hflmp

VARIABLE DESCRIPTION

Serial No Variable Name Data Type Description


1 i Int Loop index variable.
2 p Int Length of the input string.
3 st String Input string provided by the user.
4 st1 String Output string with vowels replaced by next character.
5 chr Char Character from the input string.
15.Write a program in Java to enter a string/sentence and display the length of the longest word
present in the string.

import java.util.*;
public class Length
{
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
System.out.println("Enter the sentence:");
String word=in.nextLine();
word+=" ";
int i,p;
String word1="",word2="";
char chr;
p=word.length();
for(i=0;i<p;i++)
{
chr=word.charAt(i);
if(chr ==' ')
{
if(word1.length()>word2.length())
word2=word1;
word1="";
}
else
{
word1+=chr;
}
}
System.out.println("The longest word : "+word2);
System.out.println("The length of the longest word is: "+word2.length());
}
}
OUTPUT
Input:
Enter the sentence:
The quick brown fox jumps over the lazy dog
Output:
The longest word : jumps
The length of the longest word is: 5

VARIABLE DESCRIPTION

S Variable Name Data Type Description


1 Word int Input sentence
provided by the user.
2 word1 int Temporary string
used to accumulate
characters of the
current word.
3 word2 char Longest word found
in the input sentence.
4 Chr char Current character
being processed from
the input sentence.
5 I Int Loop index variable
used to iterate over
the characters of the
sentence.
6 P Int Length of the input
sentence.
16.Write a program to input 10 names in an SDA. Arrange these names in ascending order of
letters, using selection sort technique.

import java.util.*;
public class Sel_sort
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int i,j,t,min;
int m[] = new int[10];
System.out.println("Enter the numbers in the cell");
for(i=0;i<10;i++)
{
m[i] = in.nextInt();
}
for(i=0;i<9;i++)
{
min=i;
for(j=i+1;j<10;j++)
{
if (m[j]<m[min])
min=j;
}
t= m[i];
m[i] = m[min];
m[min]=t;
}
System.out.println("The numbers arranged in ascending order are:");
for(i=0;i<10;i++)
System.out.println(m[i]);
}
}
OUTPUT
Input:
Enter the numbers in the cell
64
25
12
22
11
90
88
56
35
75
Output:
The numbers arranged in ascending order are:
11
12
22
25
35
56
64
75
88
90

VARIABLE DESCRIPTION

S VARIABLE NAME DATA TYPE DESCRIPTION


1. i int Loop variable
2. M[] matrix To store 10 no.
3. j int Loop variable
4. t int To transfer value
5 min int To store last min val
17.Write a class with the name Area using function overloading that compute the area of
following
(a)Area of circle =22/7*r*r
(b)Area of square=side*side
(c) Area of rectangle=length*breadth

import java.util.*;
public class Compute
{
double area(double r)
{
double ar1=22/7*r*r;
return(ar1);
}
int area (int sd)
{
int ar2=sd*sd;
return(ar2);
}
int area(int l,int b)
{
int ar3=l*b;
return(ar3);
}
public static void main(String args[])
{
Scanner in = new Scanner (System.in);
int s=0,a=0,br=0;
double ri=0.0;
System.out.println("Enter the radius of a circle: ");
ri=in.nextDouble();
System.out.println("Enter the side of a square: ");
s=in.nextInt();
System.out.println("Enter the length and breadth of a rectangle: ");
a=in.nextInt();
br=in.nextInt();
Compute ob=new Compute();
double m=ob.area(ri);
int n=ob.area(s);
int p=ob.area(a,br);
System.out.println("The area of a Circle: "+m);
System.out.println("The area of a Square: "+n);
System.out.println("The area of a Rectangle : "+p);
}
}
OUTPUT
Enter the radius of a circle:
7
Enter the side of a square:
4
Enter the length and breadth of a rectangle:
56
The area of a Circle: 154.0
The area of a Square: 16
The area of a Rectangle : 30

VARIABLE DESCRIPTION

S Variable name Data type Description


1. Ar1 Double To store circle area
2. Ar2 Double Area of square var
3. Ar3 double Area of rectangle var
4. S int Side of square value
5. ri double Radius of circle
6. A,br int Length and breadth
of rectangle
7. N,p int Call the functions
18. Write a Program in Java to store the numbers in a 4*4 matrix in DDA. find the sum of the
numbers of each row and sum of the numbers of each column of the matrix by using an input
statement.

import java.util.*;
public class RC_sum
{
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
int i,j,r,c;
int m[][]=new int[4][4];
System.out.println("Enter the numbers in the array");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
m[i][j]=in.nextInt();
}
System.out.println("The numbers of the matrix are");
for(i=0;i<4;i++)
{
for(j=0;j<4;i++)
{
System.out.print(m[i][j]+" ");
}
System.out.println();
}
System.out.println("The sum of the elements of each row");
for(i=0;i<4;i++)
{
r=0;
for(j=0;j<4;j++)
{
r=r+m[i][j];
}
System.out.println("Sum of"+i+1+"row ="+r);
}
System.out.println("The sum of the elements of each coloumn");
for(i=0;i<4;i++)
{
c=0;
for(j=0;j<4;j++)
{
c=c+m[j][i];
}
System.out.println("Sum of "+i+1+"column ="+c);
}
}
}
OUTPUT
Enter the number:
9
Neon number.
Enter the number:
12
Not a Neon number.

VARIABLE DESCRIPTION

S Variable name Data type Description


1. i int Loop variable
2. j int Loop variable
3. r int Sum of row
4. c int Sum of column
19. Write a Program in Java to store the numbers in a 4*4 matrix in DDA. find the sum of the
numbers of left diagonal and sum of the numbers of right diagonal of the matrix by using an
input statement.

import java.util.*;
public class SDiagonals
{
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
int i,j,ld=0,rd=0;
int m[][] = new int[4][4];
System.out.println("Enter the numbers in the array");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
m[i][j]=in.nextInt();
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(i==j)
ld=ld+m[i][j];
if(i+j==3)
rd=rd+m[i][j];
}
}
System.out.println("The sum of the left diagonal = "+ld);
System.out.println("The sum of the right diagonal ="+rd);
}
}
OUTPUT
Enter the numbers in the array:
1234
5678
9 10 11 12
13 14 15 16

The numbers of the matrix are:


1234
5678
9 10 11 12
13 14 15 16

The sum of the elements of each row:


Sum of 1 row = 10
Sum of 2 row = 26
Sum of 3 row = 42
Sum of 4 row = 58

The sum of the elements of each column:


Sum of 1 column = 28
Sum of 2 column = 32
Sum of 3 column = 36
Sum of 4 column = 40

VARIABLE DESCRIPTION

S Variable name Data type Description


1. i int Loop variable
2. j int Loop variable
3. ld int Left diagonal
elements sum
4. rd int Right diagonal
elements sum

5. M[][] Int matrix To store 4*4 matrix


20. Design a class to overload a function compare () as follows:
(i) void compare (int, int): to compare two integer values and print the greater of the two
integers.
(ii) void compare (char, char): to compare numeric value of two character and print the highest
value.
(iii) void compare (string, string): to compare the length of the two strings and print the longer of
two.

import java.util.*;
public class Compare
{
public void compare(int a, int b)
{
if(a>b)
System.out.println("the bigger number is"+a);
else
System.out.println("the bigger number is"+b);
}
public void compare (char x,char y)
{
int i=(int)x;
int j=(int)y;
if(i>j)
System.out.println("The larger character is"+i);
else
System.out.println("The larger character is"+j);
}
public void compare(String m,String n)
{
int k=m.length();
int l=n.length();
if(k>l)
System.out.println("The larger string is"+m);
else
System.out.println("The larger string is"+n);
}
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
int a1=0,b1=0;
char x1,y1;
String m1="",n1="";
System.out.println("Enter the digits ");
a1=in.nextInt();
b1=in.nextInt();
System.out.println("Enter the Characters ");
x1=in.next().charAt(0);
y1=in.next().charAt(0);
System.out.println("Enter the Strings ");
m1=in.next();
n1=in.next();
Compare ob=new Compare();
ob.compare(a1,b1);
ob.compare(x1,y1);
ob.compare(m1,n1);
}
}
OUTPUT
Enter the digits
7 12
Enter the Characters
az
Enter the Strings
apple orange

The bigger number is 12


The larger character is z
The larger string is orange

VARIABLE DESCRIPTION

S Variable name Data type Description


1. A1,b1 Int Bigger or smaller
digit
2. X1,y1 char Compare each char
3. M1,n1 string Compare length
4. A,b int Bigger or small in
function
5. X,y char Compare each char
in function
6. M1,n1 string Compare length in
function

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy