computer prj boards
computer prj boards
PROJECT
Name: Aditi.M.Shendge
Class:”X”
Section:”C”
INDEX
1) IF ELSE IF
2) SWITCH CASE
3) FOR LOOP
4) WHILE LOOP
5) DO-WHILE LOOP
6) NESTED LOOP
7) FUNCTION
8) OVERLOADED FUNCTIONS
IF ELSE IF:
1) A program to display square and cube of numbers
import java.util.*;
public class program
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int a,b,sq,cb;
System.out.println("Enter two numbers");
a=in.nextInt();
b=in.nextInt();
if(a!=b)
{
if(a<b)
{
sq=a*a;
cb=b*b*b;
}
else
{
sq=b*b;
cb=a*a*a;
}
System.out.println("The square of smaller number:"+sq);
System.out.println("The cube of greater number:"+cb);
}
else
System.out.println("Both the numbers are equal");
}
}
OUTPUT:
Enter two numbers
67
87
The square of smaller number:4489
The cube of greater number:658503
2)Marks Grade
0-34 Fail
35-59 C grade
60-79 B grade
80-94 A grade
95+ A+ grade
import java.util.Scanner;
System.out.println(" ");
}
}
OUTPUT:
Enter marks:
34
Fail
3) A program to find the greatest of 3 numbers
import java.util.Scanner;
if (a == b && b == c) {
System.out.println("All the numbers are equal");
}
else {
int g = a;
if (b > g)
g = b;
if (c > g)
g = c;
System.out.println("Greatest number: " + g);
}
}
}
OUTPUT:
Enter first number: 89
Enter second number: 65
Enter third number: 72
Greatest number: 89
1.Find if the number is positive, negative, or zero
import java.util.*;
public class marks
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number");
int num=sc.nextInt();
if(num>0)
System.out.println("Positive number");
else if(num<0)
System.out.println("Negative number");
else
System.out.println("zero");
}
}
OUTPUT:
Enter a number
34
Positive number
case 1:
if (p1<=25000)
{
dis=0.0/100.0*p1;
net=p1-dis;
}
else if (p1>25000 && p1<57001)
{
dis=5.0/100.0*p1;
net=p1-dis;
}
else if (p1>57000 && p1<1000001)
{
dis=7.0/100.0*p1;
net=p1-dis;
}
else
{
dis=10.0/100.0*p1;
net=p1-dis;
}
break;
case 2:
if(p1<=25000)
{
dis=5.0/100.0*p1;
net=p1-dis;
}
System.out.println(“name:”;+name);
System.out.println(“address:”+add);
System.out.println(“the net amount:”+net);
}
}
OUTPUT:
enter your name:
Aditi
enter the address:
villa zakrie
enter the price of the item:
25000
Enter the kind of item:1 for laptop,2 for desktop
2
name:Aditi
address:villa zakrie
the net amount:23750.0
import java.util.Scanner;
public class prg
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter cost price of the article: ");
double cp = in.nextDouble();
System.out.print("Enter selling price of the article: ");
double sp = in.nextDouble();
double pl = sp - cp;
double percent = Math.abs(pl) / cp * 100;
if (pl > 0) {
System.out.println("Profit = " + pl);
System.out.println("Profit % = " + percent);
}
else if (pl < 0) {
System.out.println("Loss = " + Math.abs(pl));
System.out.println("Loss % = " + percent);
}
else {
System.out.println("Neither profit nor loss");
}
}
}
OUTPUT:
Enter cost price of the article: 768
Enter selling price of the article: 900
Profit = 132.0
Profit % = 17.1875
import java.util.Scanner;
while (num != 0) {
int digit = num % 10;
num /= 10;
digitSum += digit;
digitProduct *= digit;
count++;
}
if (count != 2)
System.out.println("Invalid input, please
enter a 2-digit number");
else if ((digitSum + digitProduct) == orgNum)
System.out.println("Special 2-digit
number");
else
System.out.println("Not a special 2-digit
number");
}
}
OUTPUT:
Enter a 2 digit number:59
Special 2-digit number
Enter a 2 digit number:85
Not a special 2-digit number
SWITCH CASE
1) Using a switch statement, write a menu driven
program to:
(a) Generate and display the first 10 terms of the
Fibonacci series
0, 1, 1, 2, 3, 5
The first two Fibonacci numbers are 0 and 1, and each
subsequent number is the sum of the previous two.
(b) Find the sum of the digits of an integer that is input.
Sample Input: 15390
Sample Output: Sum of the digits = 18
For an incorrect choice, an appropriate error message
should be displayed.
import java.util.Scanner;
switch (ch) {
case 1:
int a = 0, b = 1;
System.out.print(a + " " + b);
for (int i = 3; i <= 10; i++) {
int term = a + b;
System.out.print(" " + term);
a = b;
b = term;
}
break;
case 2:
System.out.print("Enter number: ");
int num = in.nextInt();
int sum = 0;
while (num != 0) {
sum += num % 10;
num /= 10;
}
System.out.println("Sum of Digits " + " = " +
sum);
break;
default:
System.out.println("Incorrect choice");
break;
}
}
}
OUTPUT:
1. Fibonacci Series
2. Sum of digits
Enter your choice:1
0 1 1 2 3 5 8 13 21 34
import java.util.Scanner;
switch (choice) {
case 1:
System.out.print("Enter n: ");
int n = in.nextInt();
for (int i = 1; i <= n; i++)
System.out.print(((i * i) - 1) + " ");
System.out.println();
break;
case 2:
double sum = 0;
for (int i = 1; i <= 19; i = i + 2)
sum += i / (double)(i + 1);
System.out.println("Sum = " + sum);
break;
default:
System.out.println("Incorrect Choice");
break;
}
}
}
OUTPUT:
Type 1 to print series
0, 3, 8, 15, 24,....to n terms
Type 2 to find sum of series
("(1/2) + (3/4) + (5/6) + (7/8) +....+ (19/20)"
Enter your choice:1
Enter n:5
0,3,8,15,24,35
import java.util.Scanner;
switch (choice) {
case 1:
int c = 0;
for (int i = 1; i <= num; i++) {
if (num % i == 0) {
c++;
}
}
if (c == 2)
System.out.println(num + " is Prime");
else
System.out.println(num + " is not
Prime");
break;
case 2:
int numCopy = num;
int sq = num * num;
int d = 0;
while(num > 0)
{
d++;
num /= 10;
}
int ld = (int)(sq % Math.pow(10, d));
if (ld == numCopy)
System.out.println(numCopy + " is
automorphic");
else
System.out.println(numCopy + " is not
automorphic");
break;
default:
System.out.println("Incorrect Choice");
break;
}
}
}
OUTPUT:
1. Prime number
2.Automorphic number
Enter your choice:1
Enter number:11
11 is a prime number
4) Write a menu driven class to accept a number
from the user and check whether it is a Palindrome
or a Perfect number.
(a) Palindrome number: (A number is a Palindrome
which when read in reverse order is same as in the
right order)
Example: 11, 101, 151 etc.
(b) Perfect number: (A number is called Perfect if it
is equal to the sum of its factors other than the
number itself.)
Example: 6 = 1 + 2 + 3
import java.util.Scanner;
switch (choice) {
case 1:
int copyNum = num;
int revNum = 0;
while(copyNum != 0) {
int digit = copyNum % 10;
copyNum /= 10;
revNum = revNum * 10 + digit;
}
if (revNum == num)
System.out.println(num + " is
palindrome");
else
System.out.println(num + " is not
palindrome");
break;
case 2:
int sum = 0;
if (num == sum)
System.out.println(num + " is a perfect
number");
else
System.out.println(num + " is not a
perfect number");
break;
default:
System.out.println("Incorrect Choice");
break;
}
}
}
OUTPUT:
1. Palindrome number
2. Perfect number
Enter your choice: 1
Enter number: 151
151 is palindrome
import java.util.Scanner;
if (m > n) {
switch (choice) {
case 1:
while (n > 0) {
m++;
n--;
}
System.out.println("Sum = " + m);
break;
case 2:
int p = 0;
while (n > 0) {
p += m;
n--;
}
System.out.println("Product = " + p);
break;
case 3:
int q = 0;
while (m >= n) {
m = m - n;
q++;
}
System.out.println("Quotient = " + q);
System.out.println("Remainder = " +
m);
break;
default:
System.out.println("Incorrect Choice");
break;
}
}
else {
System.out.println("Invalid Inputs");
}
}
}
OUTPUT:
Options 1. Sum without 't' operator 2. Product
without '*' operator 3. Quotient and Remainder
without '/' & '%' operators Enter your choice: 1
Enter m: 5
Enter n: 2
Sum = 7
import java.util.”;
public class Temperature
{
public static void main(String args[])
{
int ch;
double c,f,c1 ,f1;
Scanner in new Scanner (System.in);
System.out.println(“Enter 1 to find the temp.from
Fahrenheit to Celsius ”);
System.out.println (“ Enter 2 to find the temp from
Celsius to Fahrenheit”) ;
System.out.println( “Enter your choice 1 or 2 ”);
ch= in.nextint();
switch(ch)
{
case 1:
System.out.printin("Enter temperature in
Fahrenheit:”);
f= in.nextDouble();
cl=(double)5 /9*(f-32);
System.out.printin(“The temperature in Celsius is
“+c1);
break;
case 2:
System.out.println(“Enter temperature in
Celsius:”);
c= in.nextDouble();
fi=(double)1.8*c+32;
System.out.println(“The temperature in Fahrenheit
is “+f1);
break;
default:
System.out.printin(“ Wrong Choice !!");
}
}
}
OUTPUT:
Enter 1 to find the temp.from Fahrenheit to Celsius
Enter 2 to find the temp from Celsius to Fahrenheit
import java.util.Scanner;
switch (choice) {
case 1:
for (int i = 2; i <= 100; i++) {
boolean isPrime = true;
for (int j = 2; j <= i / 2; j++) {
if (i % j == 0) {
isPrime = false;
break;
}
}
if (isPrime)
System.out.println(i);
}
break;
case 2:
System.out.println(1);
for (int i = 2; i <= 100; i++) {
boolean isPrime = true;
for (int j = 2; j <= i / 2; j++) {
if (i % j == 0) {
isPrime = false;
break;
}
}
if (!isPrime)
System.out.println(i);
}
break;
default:
System.out.println("Incorrect Choice");
break;
}
}
}
OUTPUT:
Enter 1: to display all prime numbers
Enter 2: to display all non-prime numbers
Enter your choice: 1
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
8) You want to buy a car from “sales and
purchase” where you can get a car in its
depreciated
price. Depreciation value of a car is calculated on
its
showroom price and the number of years it has
been
used. The depreciation value is calculated as per
the
tariff given below:
switch (year)
{
case 1:
dep=10.0/100.0*p1;
p2=p1-dep;
break;
case 2:
dep=20.0/100.0*p1;
p2=p1-dep;
break;
case 3:
dep=30.0/100.0*p1;
p2=p1-dep;
break;
case 4:
dep=30.0/100.0*p1;
p2=p1-dep;
break;
case 5:
dep=60.0/100.0*p1;
p2=p1-dep;
break;
}
System.out.println(“the original price of the car is
:”+p1);
System.out.println(“the depreciation value is
:”+dep);
System.out.println(“the price of the car after
deprecition is :”);
}
}
OUTPUT:
enter the showroom price of the car:
10000
case 1:
if (p1<=25000)
{
dis=0.0/100.0*p1;
net=p1-dis;
}
else if (p1>25000 && p1<57001)
{
dis=5.0/100.0*p1;
net=p1-dis;
}
else if (p1>57000 && p1<1000001)
{
dis=7.0/100.0*p1;
net=p1-dis;
}
else
{
dis=10.0/100.0*p1;
net=p1-dis;
}
break;
case 2:
if(p1<=25000)
{
dis=5.0/100.0*p1;
net=p1-dis;
}
System.out.println(“name:”;+name);
System.out.println(“address:”+add);
System.out.println(“the net amount:”+net);
}
}
OUTPUT:
enter your name:
Aditi
enter the address:
villa marine
enter the price of the item:
25000
Enter the kind of item:1 for laptop,2 for desktop
2
name: Aditi
address:villa marine
the net amount:23750.0
10) A promoter cum developer announces a
special
bonanza for early booking of the flats for their
customers as per the tariff given below
Category Discount on
price
Discount on
development
charge
Ground floor 10% 8%
First floor 20% 10%
Second floor 5% 5%
Third floor 7.5% 10%
Write a menu driven program to input price and the
category:0,1,2,3. Calculate and display the total
discount price of the flat after getting discount.
import java.util.*;
public class q25
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int cat;
Double
d1=null,d2=null,p1=null,p2=null,fp=null,fd=null;
System.out.println(“enter the price”;);
p1=in.nextDouble();
System.out.println(“enter the category: 0 for
ground floor, 1 for first floor, 2 for second floor and 3
for third floor”);
cat=in.nextInt();
switch(cat)
{
case 0:
d1=10.0/100.0*p1;
p2=p1-d1;
d2=8.0/100.0*p2;
fp=p2-d2;
break;
case 1:
d1=20.0/100.0*p1;
p2=p1-d1;
d2=10.0/100.0*p2;
fp=p2-d2;
break;
case 2:
d1=5.0/100.0*p1;
p2=p1-d1;
d2=5.0/100.0*p2;
fp=p2-d2;
break;
case 3:
d1=7.5/100.0*p1;
p2=p1-d1;
d2=10.0/100.0*p2;
fp=p2-d2;
break;
}
fd=d1+d2;
System.out.println(“the total discount is:”+fd);
System.out.println(“the price after discount is:”);
}
}
OUTPUT:
enter the price
100000
enter the category: 0 for ground floor,1 for first
floor,2 for second floor, 3 for third floor
0
The total discount is:17200.0
The price after discount is:82800.0
FOR LOOP
1. S = 1 + 1 + 2 + 3 + 5 +……………. to n terms.
import java.util.*;
public class series6
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int a=1,b=1,c=0,s=0;
System.out.println("enter the number of
terms");
int n=in.nextInt();
for(int i=1;i<=n;i++)
{
c=a+b;
s=s+c;
System.out.print(s);
a=b;
b=c;
}}}
OUTPUT:
enter number of terms
3
1+1+2
2. S = 2 – 4 + 6 – 8 +………………… to n terms.
import java.util.*;
public class series7
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int s=0,i,a,b=0;
System.out.println("enter the number of
terms");
int n=in.nextInt();
for (i=1,a=2;i<=n;i++,a=a+2)
{
if(i%2==0)
{
b=b-a;
s=s+b;
b=0;
}
else
{
b=b+a;
s=s+b;
b=0;
}
} System.out.print(s);
}}
OUTPUT:
enter the number of terms
4
2–4+6–8
3. Write a program to display the Mathematical
Table of 5 for 10 iterations in the given format:
Sample Output: Table of 5
5*1 = 5
5*2 =10
--------
--------
5*10 = 50
public class Table
{
int num = 5;
for(int i = 1; i <= 10; ++i)
{
System.out.println(num+" * "+i+" =
"+num*i);
}
}
}
OUTPUT:
5*1 = 5
5*2 =10
5*3=15
5*4=20
5*5=25
5*6=30
5*7=35
5*8=40
5*9=45
5*10=50
import java.util.Scanner;
OUTPUT:
1,11,111,1111,11111,111111,1111111,11111111,
111111111,1111111111,
3.
*
* #
* # *
* # * #
* # * # *
public class Pattern
{
public static void main(String args[]) {
for (int i = 1; i <=5; i++) {
for (int j = 1; j <= i; j++) {
if (j % 2 == 0)
System.out.print("# ");
else
System.out.print("* ");
}
System.out.println();
}
}
}
OUTPUT:
*
* #
* # *
* # * #
* # * # *
4.1 + (1+2) + (1+2+3) + .......... + (1+2+3+ ...... + n)
import java.util.Scanner;
import java.util.Scanner;
12345
1234
123
12
1
DO WHILE LOOP
1. 0, 1, 2, 3, 6.……………..
public class series1
{
public static void main(String args[])
{
int a=0,b=1,c=2,d=0,n=4;
System.out.print(a+ “ ”);
System.out.print(b+ “ ”);
System.out.print(c+ “ ” );
do
{
d=a+b+c;
System.out.print(d+ “ ”;);
a=b;
b=c;
c=d;
n=n+1;
}while(n<=10);
}
}
OUTPUT:
0,1,2,3,6,
3.0, 3, 8, 15………………..
public class series3
{
import java.io.*;
public class palindrome
{
public static void main(String args[])throws
IOException
{
Scanner in=new Scanner (System. in);
int dn,p,r=0;
System.out. printin(”“Enter a number”);
n=Integer.parselnt(in. readlane()
p=n;
do
{
d=n%10;
r=r*10+d;
n=n/10;
}
while(n!=0);
if(r==p)
System.out.printin(“Palindrome Number”);
else
System.out.printin(“Not a Palindrome Number”);
}
int sum = 0;
int num = 0;
int i=10;
do
{
System.out.print(" "+i);
i--;
}while(i>0)
}
}
OUTPUT:
10 9 8 7 6 5 4 3 2 1
WHILE LOOP
1.The Greatest Common Divisor (GCD) of two
integers is calculated by the continued division
method. Divide the larger number by the smaller,
the remainder then divides the previous divisor.
The process repeats unless the remainder reaches
to zero. The last divisor results in GCD.
Sample Input: 45, 20
Sample Output: GCD=5
import java.util.Scanner;
import java.util.Scanner;
import java.util.Scanner;
while (num != 0) {
int digit = num % 10;
num /= 10;
digitSum += digit;
digitProduct *= digit;
count++;
}
if (count != 2)
System.out.println("Invalid input, please
enter a 2-digit number");
else if ((digitSum + digitProduct) == orgNum)
System.out.println("Special 2-digit number");
else
System.out.println("Not a special 2-digit
number");
}
}
OUTPUT: Enter a 2 digit number:59
Special 2-digit number
Enter a 2 digit number:85
Not a special 2-digit number
import java.util.Scanner;
sum += digit;
prod *= digit;
num /= 10;
}
if (sum == prod)
System.out.println(orgNum + " is Spy
Number");
else
System.out.println(orgNum + " is not Spy
Number");
}
}
OUTPUT:
Enter the number:1124
1124 is a spy number
import java.util.Scanner;
int digitSum = 0;
while (num != 0) {
int digit = num % 10;
num /= 10;
digitSum += digit;
}
/*
* digitSum != 0 check prevents
* division by zero error for the
* case when users gives the number
* 0 as input
*/
if (digitSum != 0 && orgNum % digitSum == 0)
System.out.println(orgNum + " is a Niven
number");
else
System.out.println(orgNum + " is not a Niven
number");
}
}
OUTPUT:
Enter a number: 126
126 is a niven number
import java.util.Scanner;
while(copyNum != 0) {
int digit = copyNum % 10;
copyNum /= 10;
revNum = revNum * 10 + digit;
}
int diff = revNum - orgNum;
System.out.println("Reversed Number = " +
revNum);
System.out.println("Absolute Difference = " +
Math.abs(diff));
}
}
OUTPUT:
Enter number: 149
Reversed number: 941
Absolute number: 297
8. Write a program to input a number. Find the sum
of digits and the number of digits. Display the
output.
Sample Input: 7359
Sum of digits = 24
Number of digits = 4
import java.util.Scanner;
import java.util.Scanner;
while (num != 0) {
int digit = num % 10;
num /= 10;
if (digit % 2 == 0)
prod = prod * (digit + 1);
}
if (prod == 1)
System.out.println("No even digits in " +
orgNum);
else
System.out.println("Product of even digits
successors is "
+ prod);
}
}
OUTPUT:
Enter the number: 2745
Product of even number sucessors is 15
FUNCTIONS
1.Write a program in Java using a method
Discount( ), to calculate a single discount or a
successive discount. Use overload methods
Discount(int), Discount(int,int) and
Discount(int,int,int) to calculate single discount
and successive discount respectively. Calculate
and display the amount to be paid by the
customer after getting discounts on the printed
price of an article.
Sample Input:
Printed price: ₹12000
Successive discounts = 10%, 8%
= ₹(12000 - 1200)
= ₹(10800 - 864)
Amount to be paid = ₹9936
import java.util.Scanner;
obj.discount(price);
}
}
OUTPUT:
It is an Armstrong Number.
import java.util.Scanner;
if (cubeSum == n)
return 1;
else
return 0;
}
int isPronic = 0;
return isPronic;
}
if (r == 1)
System.out.println(num + " is a pronic
number");
else
System.out.println(num + " is not a pronic
number");
}
}
OUTPUT:
Enter the number to check :12
12 is a pronic number
int i;
for (i = 2; i <= n; i++) {
if (n % i == 0)
break;
}
int sf = n / i;
import java.util.Scanner;
switch(choice) {
case 'a':
System.out.print("Enter radius of circle: ");
double r = in.nextDouble();
double ca = (22 / 7.0) * r * r;
System.out.println("Area of circle = " + ca);
break;
case 'b':
System.out.print("Enter side of square: ");
double side = in.nextDouble();
double sa = side * side;
System.out.println("Area of square = " + sa);
break;
case 'c':
System.out.print("Enter length of rectangle:
");
double l = in.nextDouble();
System.out.print("Enter breadth of
rectangle: ");
double b = in.nextDouble();
double ra = l * b;
System.out.println("Area of rectangle = " +
ra);
break;
default:
System.out.println("Wrong choice!");
}
}
}
OUTPUT:
Enter a to calculate area of circle
Enter b to calculate area of square
Enter c to calculate area of rectangle
Enter your choice :a
Enter radius of circle:9
Area of circle = 254.71428571
6. Write a program using method name
Glcm(int,int) to find the Lowest Common Multiple
(LCM) of two numbers by GCD (Greatest Common
Divisor) of the numbers. GCD of two integers is
calculated by continued division method. Divide the
larger number by the smaller, the remainder then
divides the previous divisor. The process is repeated
till the remainder is zero. The divisor then results in
the GCD.
LCM = product of two numbers / GCD
import java.util.Scanner;
double tax;
if (income <= 250000)
tax = 0;
else if (income <= 500000)
tax = (income - 250000) * 0.1;
else if (income <= 1000000)
tax = 30000 + ((income - 500000) * 0.2);
else
tax = 50000 + ((income - 1000000) * 0.3);
return decimal;
}
void number() {
Scanner in = new Scanner(System.in);
System.out.println("Enter 1 to display number
in Binary Equivalent");
System.out.println("Enter 2 to display number
in Decimal Equivalent");
System.out.print("Enter your choice: ");
int c = in.nextInt();
switch (c) {
case 1:
System.out.print("Enter a decimal number:
");
int num = in.nextInt();
long binNum = decimal2Binary(num);
System.out.println("Binary Equivalent");
System.out.println(binNum);
break;
case 2:
System.out.print("Enter a binary number: ");
long ipNum = in.nextLong();
long decNum = binary2Decimal(ipNum);
System.out.println("Decimal Equivalent");
System.out.println(decNum);
break;
default:
System.out.println("Incorrect Choice");
break;
}
}
}
OUTPUT:
Enter 1 to display number in Binary Equivalent
Enter 2 to display number in Decimal Equivalent
Enter your choice: 1
Enter a decimal number: 21
Binary Equivalent 10101
9. Write a class using a function primeCheck(int num)
to check whether a given number is Prime or not.
Function should return a value 1 if number is prime
otherwise it return 0 if not.
public class ques
{
public static int primeCheck(int num)
{
int flag = 1;
for(int i = 2;i<num;i++)
{
if(num%i = = 0)
{
flag = 0;
break;
}
}
return(flag);
}
}
OUTPUT:
prime check (4)
returned
int =0
OVERLOADED FUNCTIONS
1.Design a class to overload a function compare() as
follows:
(i) void compare( int, int) : to compare two integers
and print the greater of the two
(ii) void compare( char, char) : to compare the
numeric value of two characters and printing the
higher of the two
(iii) void compare( String, String) : to compare the
length of two strings and print the longer of the two.
import java.util.*;
public class display
{
void compare( int n1, int n2)
{
int max=0;
if(n1>n2)
max=n1;
else if(n2>n1)
max=n2;
System.out.println("the greater number is:
"+max);
}
void compare( char c1, char c2)
{
char greater=' ';
if((int)c1>(int)c2)
greater=c1;
else if((int)c2>(int)c1)
greater=c2;
System.out.println("the character with greater
numerical value is: "+greater);
}
void compare( String s1, String s2)
{
String longer=" ";
int len1=s1.length();
int len2=s2.length();
if(len1>len2)
longer=s1;
else if(len2>len1)
longer=s2;
System.out.println("the longer string: "+longer);
}
}
OUTPUT:
the greater number is 2
import java.util.Scanner;
Formula:
Perimeter of a square = 4 * s
Perimeter of a rectangle = 2 * (l + b)
Perimeter of a circle = 2 * (22/7) * r
import java.util.Scanner;
public class Perimeter
{
public double perimeter(double s) {
double p = 4 * s;
return p;
}
public double perimeter(double l, double b) {
double p = 2 * (l + b);
return p;
}
public double perimeter(int c, double pi, double r)
{
double p = c * pi * r;
return p;
}
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
Perimeter obj = new Perimeter();
System.out.print("Enter side of square: ");
double side = in.nextDouble();
System.out.println("Perimeter of square = " +
obj.perimeter(side));
System.out.print("Enter length of rectangle: ");
double l = in.nextDouble();
System.out.print("Enter breadth of rectangle: ");
double b = in.nextDouble();
System.out.println("Perimeter of rectangle = "
+ obj.perimeter(l, b));
System.out.print("Enter radius of circle: ");
double r = in.nextDouble();
System.out.println("Perimeter of circle = " +
obj.perimeter(2, 3.14159, r));
}
}
OUTPUT:
Enter side of square 3
Perimeter of square =12.0
Enter length of rectangle: 10
Enter breadth of rectangle: 7
Enter radius of circle: 34.0
Perimeter of rectangle =37.699079999
5.Design a class overloading a function calculate() as
follows:
}
}
OUTPUT:
Enter a number:77
it is divisible by :7
Last digit is :7
Enter first number:52
Enter second number: 75
75
52
@@@@@ @@@@@
***
}
9.Design a class to overload the function display(.....)
as follows:
if (diff == 0)
System.out.println(num + " is a perfect
square");
else
System.out.println(num + " is not a perfect
square");
if (idx == -1)
System.out.println(ch + " not found");
else
System.out.println(ch + " found");
int count = 0;
int len = str.length();
System.out.println("Number of special
characters = " + count);
}
class Adder
{
static int multiply(int a,int b)
{
return a*b;
}
static int multiply(int a,int b,int c)
{
return a*b*c;}
}
class TestOverloading1
{
public static void main(String[] args)
{
System.out.println(Adder.multiply(110,110));
System.out.println(Adder.multiply(110,110,110));
}
}
OUTPUT:
multiply(3,5,7)
105
BIBLIOGRAPHY
www.knowlegeboat.com
www.javapoint.com
ICSE APC COMPUTER APPLICATIONS.
ACKNOWLEDGEMENT
First and foremost, I would like to thank God
almighty, without whose help doing these projects
would have been an impossible task. Secondly I
would like to thank our principal, Sr. Malar Joseph
who encourages us to learn and explore the
creativity within us. Thirdly, I would like to thank
miss Savita who gave me suitable guidelines to
complete this project in the right manner. Last but
not the least I would like to thank my family and
friends whose ample support and guidance helped
me to complete this project in a creative manner.
THANK
YOU