Name : Pratham singhal Class : 10 ‘D’
Subject : Computer Applications Roll no : 10
Year : 2022-23
Page No Program No Program use
3 ------------------ Acknowledgement
4 1 To print a numbers table
5 2 Loop pattern
6 3 Method Overloading Program
8 4 Factorial
9 5 Loop pattern
10 6 Method Overloading loop patterns
12 7 Enter marks in 3 subject to get maximum and
average marks
15 8 Loop pattern
16 9 Loop pattern
17 10 Program to calculate the bill of calls made
19 11 Palindrome number
20 12 Greatest number
21 13 To calculate area and volume (user defined)
23 14 Array to convert temperature from Celsius to
fahrenhiet
25 15 Factorial using while loop
26 16 Armstrong numbers between 1-500
27 17 To check if character is in upper or lowercase, a
Page : 1
digit or a special symbol.
29 18 To see if number is Armstrong or not.
31 19 Bubble sort
33 20 To check frequency of a letter
34 21 To print string without using vowels
35 22 To count non-vowels alphabets in a string
36 23 To enter a name and print its initials
37 24 To print asterisk instead Of vowels
39 25 To print every words first letter
40 26 To Print only Palindrome words in a string
41 27 To print reverse of words in a string
43 28 To print sum of prime digits of a number
44 29 Loop pattern
46 30 To print sum of series of for loop
47 ------------------ Bibliography
Page : 2
I would like to express my special thanks of gratitude to my computer
teacher “Mr. Harvinder Singh” for their able guidance and support in
completing my project.
I would also like to extend my gratitude to the Principle “Mr. Samuel
Jaideep” and Vice Principle “Mr. Ramesh Uniyal ” for providing me with
all the facility that was required.
Date : 27/10/2022
Pratham singhal
Class : Xth ‘D’
Page : 3
30Java Programs
Program 1:
import java.util.*;
class table
public static void main(String args[])
int x,i,p;
Scanner sc = new Scanner(System.in);
System.out.println("Enter number to print the table of a number");
x=sc.nextInt();
for(i=1;i<=10;i++)
p=x*i;
System.out.println(x+"x"+i+"="+p);
Output :
Enter number to print the table of a number
Page : 4
10
10x1=10
10x2=20
10x3=30
10x4=40
10x5=50
10x6=60
10x7=70
10x8=80
10x9=90
10x10=100
Program 2:
class loop3
public static void main(String args[])
int i,j;
for(i=1;i<=5;i++)
for(j=5;j>=i;j--)
System.out.print(j);
Page : 5
System.out.println();
}}
Output :
54321
5432
543
54
Program 3 :
class overload
public void compare(int i,int j)
if(i>j)
System.out.println(i+" is greater than "+j);
else
System.out.println(j+" is greater than "+i);
}
Page : 6
public void compare(char a,char b)
if((int)a>(int)b)
System.out.println("Numeric value of "+ a+" is greater");
else
System.out.println("Numeric value of "+ b+" is greater");
public void compare(String s,String str)
if(s.length()>str.length())
System.out.println("Length of "+s+" is greater");
else
System.out.println("Length of "+str+" is greater");
public static void main(String args[])
{
Page : 7
overload ob = new overload();
ob.compare(1,2);
ob.compare('A','B');
ob.compare("red","amisha");
}}
Output:
2 is greater than 1
Numeric value of B is greater
Length of amisha is greater
Program 4:
import java.util.*;
class factorial
public static void main(String args[])
int x,f=1;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number");
x=sc.nextInt();
while(x>0)
f=f*x;
x--;
Page : 8
}
System.out.println("Factorial is :" + f);
Output :
Enter a number
Factorial is :120
Program 5:
class loop
public static void main(String args[])
int i,j,sp=1;
for(i=1;i<=5;i++)
for(j=sp;j>=1;j-=2)
System.out.print(j);
System.out.println();
sp+=2;
Page : 9
}
Output:
1
31
531
7531
97531
Program 6:
class pattern
public void polygon(int n,char ch)
int i,j;
for(i=1;i<=n;i++)
for(j=1;j<=2;j++)
System.out.print(ch);
System.out.println();
Page : 10
public void polygon(int x,int y)
int i,j;
for(i=1;i<=2;i++)
for(j=1;j<=5;j++)
System.out.print("@");
System.out.println();
public void polygon()
int i,j;
for(i=1;i<=3;i++)
for(j=1;j<=i;j++)
System.out.print("*");
System.out.println();
}
Page : 11
public static void main(String args[])
pattern ob = new pattern();
ob.polygon(2,'O');
ob.polygon(2,5);
ob.polygon();
Output:
OO
OO
@@@@@
@@@@@
**
***
Program 7:
import java.util.*;
class student
public String nm;
public int age;
Page : 12
public double m1,m2,m3,maximum;
public double average;
public student(String name,int ag,double ma1,double ma2,double ma3)
nm=name;
age=ag;
m1=ma1;
m2=ma2;
m3=ma3;
public void compute()
average=(m1+m2+m3)/3;
if(m1>m2 && m1>m3)
maximum = m1;
else if(m2>m1 && m2>m3)
maximum = m2;
else
maximum = m3;
Page : 13
}
public void display()
System.out.println("Name = " + nm);
System.out.println("Age = " + age);
System.out.println("Marks in 3 subjects = " +m1+" "+m2+" "+m3);
System.out.println("Maximum = " + maximum);
System.out.println("Average = " + average);
public class test_student
public static void main(String args[])
student ob = new student("Pratham",15,75,85,95);
ob.compute();
ob.display();
Output :
Name = Pratham
Age = 15
Marks in 3 subjects = 75.0 85.0 95.0
Page : 14
Maximum = 95.0
Average = 85.0
Program 8:
class loop1
public static void main(String args[])
int i,j;
for(i=1;i<=8;i++)
for(j=1;j<=i;j++)
System.out.print(j);
System.out.println( );
Output :
1
12
123
1234
Page : 15
12345
123456
1234567
12345678
Program 9 :
class loop2
public static void main(String args[])
int i,j,k,sp=1;
for(i=9;i>=1;i--)
for(k=1;k<=sp;k++)
System.out.print(" ");
for(j=1;j<=i;j++)
System.out.print('#');
System.out.println( );
sp++;
}
Page : 16
}
Output:
#########
########
#######
######
#####
####
###
##
Program 10 :
import java.util.*;
class calls
public static void main(String args[])
int code,call;
String nm;
double bill;
Scanner sc = new Scanner(System.in);
System.out.println("Enter Customer Code");
code = sc.nextInt();
Page : 17
System.out.println("Enter Calls Made");
call=sc.nextInt();
System.out.println("Enter Name of customer");
nm=sc.next();
if(call<=150)
bill=500;
else if(call<=200)
bill=500+(call-150)*0.80;
else if(call<=300)
bill=500+50*0.80+(call-200)*1;
else
bill=500+50*0.80+100*1+(call-300)*1.20;
System.out.println("Bill = " + bill);
Output :
Page : 18
Enter Customer Code
2347
Enter Calls Made
200
Enter Name of customer
Pratham
Bill = 540.0
Program 11 :
import java.util.*;
class palindrome
public static void main(String args[])
int x,i,d,rev=0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter number");
x=sc.nextInt();
i=x;
while(x>0)
d=x%10;
rev=rev*10+d;
x=x/10;
}
Page : 19
if(i==rev)
System.out.println("Number is a Palindrome number");
else
System.out.println("Number is not a Palindrome number");
Output :
Enter number
121
Number is a Palindrome number
Program 12:
class greatest
public int big(int x,int y)
if(x>y)
return x;
Page : 20
else
return y;
public static void main(String args[])
greatest ob = new greatest();
int i=ob.big(3,4);
System.out.println("Greatest number = " + i);
Output :
Greatest number = 4
Program 13:
import java.util.*;
class bedroom
public int l;
public int b;
public int h;
public double area;
public double volume;
Page : 21
public void inputdata()
Scanner sc = new Scanner(System.in);
System.out.println("Enter Length");
l=sc.nextInt();
System.out.println("Enter breadth");
b=sc.nextInt();
System.out.println("Enter height");
h=sc.nextInt();
public void calculate()
area=2*(l*b+b*h+h*l);
volume=l*b*h;
public void output()
System.out.println("Area = " + area);
System.out.println("volume = " + volume);
public class test_bedroom
public static void main(String args[])
Page : 22
{
bedroom ob = new bedroom();
ob.inputdata();
ob.calculate();
ob.output();
Output :
Enter Length
12
Enter breadth
Enter height
Area = 216.0
volume = 144.0
Program 14:
import java.util.*;
class temp
public static void main(String args[])
int i;
Page : 23
Scanner sc = new Scanner(System.in);
double f[]=new double[5];
double c[]=new double[5];
System.out.println("Enter temperature in Fahrenhiet");
for(i=0;i<f.length;i++)
f[i]=sc.nextDouble();
System.out.println("Temperature in Celcius");
for(i=0;i<f.length;i++)
c[i]=(f[i]-32)*5/9;
System.out.println(c[i]);
Output :
Enter temperature in Fahrenheit
237.5
330.0
560.0
123.0
347.9
Page : 24
Temperature in Celsius
114.16666666666667
165.55555555555554
293.3333333333333
50.55555555555556
175.5
Program 15:
import java.util.*;
class while1
public static void main(String args[])
int i,f=1;
Scanner sc = new Scanner(System.in);
System.out.println("Enter Number to Print its Factorial");
i=sc.nextInt();
while(i>0)
f=f*i;
i--;
System.out.println("Factorial = " + f);
}
Page : 25
Output :
Enter Number to Print its Factorial
Factorial = 120
Program 16:
class Armstrong
public static void main(String args[])
int i,s=0,d,x;
for(i=1;i<=500;i++)
s=0;
x=i;
while(x>0)
d=x%10;
s=s+(d*d*d);
x=x/10;
if(s==i)
Page : 26
System.out.println(i);
Output:
1
153
370
371
407
Program 17:
import java.util.*;
class case_q
public static void main(String args[])
char ch;
Scanner sc = new Scanner(System.in);
System.out.println("Enter character");
ch=sc.next().charAt(0);
if(Character.isUpperCase(ch))
Page : 27
System.out.println("Character is in Uppercase");
else if(Character.isLowerCase(ch))
System.out.println("Character is in Lowercase");
else if(Character.isDigit(ch))
System.out.println("Character is Digit");
else
System.out.println("Character is Special Character");
Output :
Enter character
Character is in Uppercase
Program 18 :
class armweak
Page : 28
public int Armstrong(int i)
int y,d,c=0,x;
double s=0;
x=i;
y=i;
while(i>0)
d=i%10;
c++;
i=i/10;
while(y>0)
d=y%10;
s=s+Math.pow(d,c);
y=y/10;
if(x==s)
return 1;
else
{
Page : 29
return 0;
public static void main(String args[])
armweak ob = new armweak();
int z=ob.Armstrong(407);
if(z==1)
System.out.println("Number is a Armstrong number");
else
System.out.println("Number is not a Armstrong number");
Output :
Number is a Armstrong number
Program 19 :
import java.util.*;
class bubble
Page : 30
public static void main(String args[])
int i,j,temp;
Scanner sc = new Scanner(System.in);
int num[]=new int[10];
System.out.println("Enter Numbers");
for(i=0;i<num.length;i++)
num[i]=sc.nextInt();
for(i=0;i<num.length;i++)
for(j=0;j<num.length-i-1;j++)
if(num[j]>num[j+1])
temp=num[j];
num[j]=num[j+1];
num[j+1]=temp;
System.out.println("Array in Assending order");
for(i=0;i<num.length;i++)
Page : 31
{
System.out.println(num[i]);
Output :
Enter Numbers
Array in Ascending order
7
Page : 32
8
Program 20 :
import java.util.*;
public class alphabets
public static void main(String args[])
int c=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter a String");
String st=sc.nextLine();
System.out.println("Enter an alphabets whose frequency is to be checked: ");
char ch=sc.next().charAt(0);
for(int i=0;i<st.length();i++)
char x=st.charAt(i);
if(x==ch)
c++;
System.out.println("The frequency of "+ch+" is "+c);
}
Page : 33
}
Output :
Enter a String
WE ARE LIVING IN COMPUTER WORLD
Enter an alphabets whose frequency is to be checked:
The frequency of E is 3
Program 21 :
import java.util.*;
public class vowels
public static void main(String args[])
String w="";
Scanner sc=new Scanner(System.in);
System.out.println("Enter a String");
String st=sc.nextLine();
for(int i=0;i<st.length();i++)
char x=st.charAt(i);
if(x!='A' && x!='E' && x!='I' && x!='O' && x!='U' && x!='a' && x!='e'
&& x!='i' &&x!='o' && x!='u')
w=w+x;
Page : 34
}
System.out.println(w);
Output :
Enter a String
COMPUTER APPLICATIONS
CMPTR PPLCTNS
Program 22 :
import java.util.*;
public class nonvowels
public static void main(String args[])
int c=0;
Scanner sc=new Scanner(System.in);
System.out.println("enter a string");
String st=sc.nextLine();
for(int i=0;i<st.length();i++)
char x=st.charAt(i);
if(x!=' '&& x!='A' && x!='E' && x!='I' && x!='O' && x!='U' && x!='a'
&& x!='e' &&x!='i' && x!='o' && x!='u')
Page : 35
c++;
System.out.println("no of alphabets excluding vowels = "+c);
Output :
enter a string
Happy New Year
no of alphabets excluding vowels = 8
Program 23 :
import java.util.*;
public class Q23
public static void main(String args[])
Scanner sc=new Scanner(System.in);
System.out.println("Enter a String");
String st=sc.nextLine();
st=st.trim();
st=' '+st;
for(int i=0;i<st.length();i++)
char x=st.charAt(i);
Page : 36
if(x==' ')
System.out.print(st.charAt(i+1)+" ");
Output :
Enter a String
LAL KRISHNA ADVANI
L K A
Program 24 :
import java.util.*;
public class Q24
public static void main(String args[])
int c=0;
String w="";
Scanner sc=new Scanner(System.in);
System.out.println("enter a string");
String st=sc.nextLine();
st=st.toUpperCase();
for(int i=0;i<=st.length()-1;i++)
Page : 37
char x=st.charAt(i);
if(x=='A'||x=='E'||x=='I'||x=='O'||x=='U')
x='*';
w=w+x;
System.out.println(w);
Output :
enter a string
TATA STEEL IS IN JAMSHEDPUR
T*T* ST**L *S *N J*MSH*DP*R
Program 25 :
import java.util.*;
public class Q15
public static void main(String args[])
String w="";
Scanner sc=new Scanner(System.in);
System.out.println("enter a string");
Page : 38
String st=sc.nextLine();
st=st.trim();
st=" "+st;
for(int i=0;i<st.length();i++)
char x= st.charAt(i);
if(x==' ')
w=w+st.charAt(i+1);
System.out.println(w);
Output :
enter a string
Vital Information Resource Under Seize
VIRUS
Program 26 :
import java.util.*;
public class Q16
public static void main(String args[])
char x;
Page : 39
String s1="",s2="",rev="";
System.out.println("\f");
Scanner sc=new Scanner(System.in);
System.out.println("enter a string");
String st=sc.nextLine();
st= st.toUpperCase();
st=st.trim();
st=st+" ";
for(int i=0;i<st.length();i++)
x=st.charAt(i);
if(x!=' ')
s1=s1+x;
s2=x+s2;
else
if(s1.equals(s2))
System.out.println(s1);
s1="";
s2="";
}
Page : 40
}
Output :
enter a string
MOM AND DAD ARE NOT AT HOME
MOM
DAD
Program 27 :
import java.util.*;
public class Q17
public static void main(String args[])
String w="",s1="";
char x=' ';
Scanner sc= new Scanner(System.in);
System.out.println("enter a String:");
String st= sc.nextLine();
st=st.trim()
st=" "+st;
for(int i= st.length()-1;i>=0;i—
x=st.charAt(i);
Page : 41
if(x!=' ')
w=x+w;
else
s1=s1+w+" ";
w="";
System.out.println(s1);
Output :
enter a String:
COMPUTER IS FUN
FUN IS COMPUTER
Program 28 :
import java.util.*;
class primesum
public static void main(String args[])
int x,i,d,c=0,s=0;
Scanner sc = new Scanner(System.in);
Page : 42
System.out.println("Enter number");
x=sc.nextInt();
while(x>0)
d=x%10;
c=0;
for(i=2;i<=d/2;i--)
if(d%i==0)
c++;
break;
if(c==0)
s=s+d;
x=x/10;
System.out.println("Sum = " + s);
Output :
Page : 43
Enter number
100
Sum = 1
Program 29 :
class astric
public static void main(String args[])
int i,j,x,y;
for(i=1;i<=5;i++)
for(j=1;j<=i;j++)
System.out.print("*");
System.out.println(" ");
for(x=4;x>=1;x--)
for(y=1;y<=x;y++)
System.out.print("*");
System.out.println(" ");
Page : 44
}
Output :
*
**
***
****
*****
****
***
**
Program 30 :
class sign
public static void main(String args[])
int sign=-1,x,i,s=0;
for(i=1;i<=10;i++)
x=i*sign*-1;
sign=sign*-1;
Page : 45
System.out.print(x+",");
s=s+x;
System.out.println("Sum = " +s);
Output :
1,-2,3,-4,5,-6,7,-8,9,-10,Sum = -5
I Pratham Singhal here by declare that i have successfully completed my project by the
help of books and some websites : i.e.;
1) Microsoft word
2) Logix Computer Applications with bluej
Page : 46
Page : 47