[go: up one dir, main page]

0% found this document useful (0 votes)
2K views34 pages

Java Programs for Class 11 Projects

Programs based on String Manipulation, Arrays, (SDA and DDA), Patterns and series printing, for-loop, while-loop, do-while loop etc...

Uploaded by

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

Java Programs for Class 11 Projects

Programs based on String Manipulation, Arrays, (SDA and DDA), Patterns and series printing, for-loop, while-loop, do-while loop etc...

Uploaded by

Binnu Thomas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
  • Program 1 - Grade Calculation: This program calculates the grade obtained by the student in three subjects based on average marks.
  • Program 2 - Quadratic Equation Roots: This program finds the roots of a quadratic equation using input coefficients.
  • Program 3 - Sum-product Number: The program checks if a given number is a sum-product number and displays the result.
  • Program 4 - Pattern Printing 1: Prints a numeric pattern based on nested loops.
  • Program 5 - Pattern Printing 2: Generates and outputs a different numeric pattern using loop constructs.
  • Program 6 - Series Generation 1: Calculates and generates a series for a given input value of n.
  • Program 7 - Series Generation 2: Generates another series based on a given input using a different logic.
  • Program 8 - Armstrong Number: Determines if a number is an Armstrong number and outputs the result.
  • Program 9 - Piglatin Conversion: Converts the words in a sentence into Piglatin form and displays the result.
  • Program 10 - Reverse Words in Sentence: Reverses each word in a sentence while preserving the word order.
  • Program 11 - Display Initials and Surname: Formats and displays initials along with the surname for a given full name.
  • Program 12 - Triangle Pattern Menu: Offers a menu to print either a triangle or an inverted triangle pattern based on user input.
  • Program 13 - Employee Tax Calculation: Calculates tax payable by an employee based on salary and tax brackets.
  • Program 14 - Library Fine Calculation: Calculates the fine for a book based on the number of overdue days.
  • Program 15 - Linear Search: Implements a linear search to find a number in an array and returns the position.
  • Program 16 - Binary Search: Performs a binary search on a sorted array to find the position of a given number.
  • Program 17 - Bubble Sort: Sorts a list of numbers in ascending order using the bubble sort technique.
  • Program 18 - Alphabetical Order Sorting: Uses exchange selection sort to arrange names in alphabetical order.
  • Program 19 - Daily Sales in Supermarket: Records and displays the daily sales for each shop in a supermarket using matrices.
  • Program 20 - Transpose of a Matrix: Computes the transpose of a given matrix and displays the result.

Program 1

// To find the grade obtained by the student in three subjects


import [Link].*;
class Student
{
public static void main(String[]args)
{
int a,b,c;
double aver=0.0;
Scanner in=new Scanner([Link]);
[Link]("Enter the marks in three subjects");
a=[Link]();
b=[Link]();
c=[Link]();
aver=(a+b+c)/3;
if(aver>=90)
[Link]("The grade is A+");
else
if(aver>=80&&aver<90)
[Link]("The grade is A");
else
if(aver>=70&&aver<80)
[Link]("The grade is B+");
else
if(aver>=60&&aver<70)
[Link]("The grade is B");
else
if(aver>=50&&aver<60)
[Link]("The grade is C+");
else
if(aver>=40&&aver<50)
[Link]("The grade is C");
else
if(aver>40)
[Link]("The student got no grade");
[Link]("The percentage mark scored by the student is "+aver);
}
}

Output:
Enter the marks in three subjects
86
79
90
The grade is A
The percentage mark scored by the student is 85.0
Program 2
//To find the roots of the quadratic equation
import [Link].*;
class Quadratic
{
public static void main(String[]args)
{
int a,b,c,d=0;
double x1=0.0,x2=0.0;
Scanner in=new Scanner([Link]);
[Link]("Enter the value of a,b and c");
a=[Link]();
b=[Link]();
c=[Link]();
d=b*b-4*a*c;
if(d>=0)
{
x1=-b+[Link](d)/(2*a);
x2=-[Link](d)/(2*a);
[Link]("The roots are "+x1+" and "+x2);
}
else
if(d<0)
[Link]("The roots are not possible");
}
}
Output:
Enter the value of a,b and c
1
-8
12
The roots are 10.0and 6.0
Program 3
// To check whether the number is a Sum-product number or not
import [Link].*;
class Sum_product
{
public static void main(String[]args)
{
int r,n,m,s=0,p=1;
Scanner in=new Scanner([Link]);
[Link]("Enter a Number");
n=[Link]();
while(n>0)
{
r=n%10;
s=s+r;
p=p*r;
n=n/10;
}
if(s==p)
[Link]("The number is sum-product");
else
[Link]("The number is not sum-product");
}
}
Output:
Enter a Number
123
The number is sum-product
Program 4
//To print the pattern
import [Link].*;
class Pattern_1
{
public static void main(String[]args)
{
int i,j,k,p=1;
for(i=1;i<=9;i+=2)
{
for(j=i;j<=9;j+=2)
{
[Link](j);
}
if(i>1)
{
for(k=1;k<=p;k+=2)
{
[Link](k);
}
[Link]();
p=p+2;
}
else
[Link]();
}
}
}
Output:
13579
35791
57913
79135
91357
Program 5
//To print the pattern

class Pattern_2

public static void main(String[]args)

int i,j,a,p=2;

for(i=1;i<=5;i++)

for(j=1;j<=i;j++)

[Link](i);

for(a=p;a<=5;a++)

[Link](a);

[Link]();

p++;

Output:
12345
22345
33345
44445
55555
Program 6
//To generate the series
import [Link].*;
class Series1
{
public static void main(String[]args)
{
int i,n,k=0;
Scanner in=new Scanner([Link]);
[Link]("Enter the value of n");
n=[Link]();
for(i=1;i<=n;i++)
{
k=(i*i*i)-1;
[Link](k+" ,");
}
}
}

Output:
Enter the value of n
6
0 ,7 ,26 ,63 ,124 ,215 ,
Program 7
//To generate the series
import [Link].*;
class Series2
{
public static void main(String[]args)
{
int i,n,s=0;
double l=0.0;
Scanner in=new Scanner([Link]);
[Link]("Enter the value of n");
n=[Link]();
for(i=0;i<=n;i++)
{
s=s*10+5;
l=s/10.0;
[Link](l +", ");
}
}
}

Output:
Enter the value of n

0.5, 5.5, 55.5, 555.5, 5555.5, 55555.5,


Program 8
//To whether the number is an Armstrong number or not
import [Link].*;
class Armstrong_number
{
public static void main(String[]args)
{
int n, r=0,s=0,c=1,m=0;
Scanner in=new Scanner([Link]);
[Link]("Enter the number");
n=[Link]();
m=n;
while(n>0)
{
r=n%10;
c=r*r*r;
s=s+c;
n=n/10;
}
if(s==m)
[Link]("The number is a Armstrong number");
else
[Link]("The number is not a Armstrong number");
}
}
Output:
Enter the number
153
The number is a Armstrong number

Enter the number


25
The number is not a Armstrong number
Program 9
//To display all the words in the piglatin form
import [Link].*;
class Piglatin_tokn
{
public static void main(String[]args)
{
String str,str2="",str3="",str4="",str5="";
int len=0,i;
char ch;
Scanner in=new Scanner([Link]);
[Link]("Enter the sentence");
str=[Link]();
str=[Link]();
StringTokenizer str1=new StringTokenizer(str," .");
while([Link]())
{
str2=[Link]();
len=[Link]();
for(i=0;i<len;i++)
{
ch=[Link](i);
if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
{
str3=[Link](i,len);
str4=str3+ [Link](0,i);
}
else;
}
str5=str5+str4+"AY"+" ";
}
[Link]("The new sentence formed is "+str5);
}
}

Output:
Enter the sentence
the capital of india is new delhi
The new sentence formed is ETHAY ALCAPITAY OFAY AINDIAY ISAY EWNAY
IDELHAY
Program 10
//To reverse each word in the sentence
import [Link].*;
class Sentence
{
public static void main(String[]args)
{
int i,len=0;
String str,str1="",str2="";
char ch;
Scanner in=new Scanner([Link]);
[Link]("Enter a sentence");
str=[Link]();
str=str+" ";
len=[Link]();
for(i=0;i<len;i++)
{
ch=[Link](i);
if(ch==' ')
{
str2=str2+" "+str1;
str1=" ";
}
else
str1=ch+str1;
}
[Link]("The reverse order is: "+str2);
}
}

Output:
Enter a sentence
Honesty is the best policy
The reverse order is: ytsenoH si eht tseb ycilop
Program 11
//To display initial along with the surname
import [Link].*;
class Surname
{
public static void main(String[]args)
{
int i,p=0,len=0;
String str,str1="",str2="",str3="";
char ch,ch1=0;
Scanner in=new Scanner([Link]);
[Link]("Enter any Full Name");
str=[Link]();
str=" "+str;
len=[Link]();
p=[Link](' ');
str2=[Link](p+1,len);
for(i=0;i<p;i++)
{
ch=[Link](i);
if(ch==' ')
{
ch1=[Link](i+1);
str1=str1+ch1+'.';
}
else;
}
str3=str2+" "+str1;
[Link]("The New Name is: "+str3);
}
}

Output:
Enter any Full Name
Subash Chandra Bose
The New Name is: Bose S.C.
Program 12
//Menu driven program to print the pattern of triangle or inverted triangle
import [Link].*;
class Menu
{
public static void main(String[]args)
{
int ch,n,i,j;
Scanner in=new Scanner([Link]);
[Link]("Enter 1 for triangle and 2 for inverted triangle");
ch=[Link]();
[Link]("Enter a number");
n=[Link]();
switch(ch)
{
case 1:for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
[Link](i);
}
[Link]();
}
break;
case 2:for(i=n;i>=1;i--)
{
for(j=1;j<=i;j++)
{
[Link](i);
}
[Link]();
}
break;
default:[Link]("Invalid");
}
}
}

Output:
Enter 1 for triangle and 2 for inverted triangle
1
Enter a number
5
1
22
333
4444
55555

Enter 1 for triangle and 2 for inverted triangle


2
Enter a number
4
4444
333
22
1
Program 13
//To find the tax of the Employee
import [Link].*;
class Employee
{
int pan;
String name;
double taxincome;
double tax;
Employee()
{
pan=0;
name="";
taxincome=0.0;
tax=0.0;
}

void input()
{
Scanner in=new Scanner([Link]);
[Link]("Enter the pan number, name, and taxable income of the
employee");
pan=[Link]();
name=[Link]();
taxincome=[Link]();
}

void cal()
{
if(taxincome<=250000)
tax=0.0;
else
if(taxincome>=250001&&taxincome<=500000)
tax=0.1*(taxincome-250000);
else
if(taxincome>=500001&&taxincome<=1000000)
tax=10000+.2*(taxincome-500000);
else
if(taxincome>1000001)
tax=25000+.3*(taxincome-1000000);
}

void display()
{
[Link]("Pan number"+"\t"+"Name"+"\t"+"Taxable
Income"+"\t"+"Tax");
[Link](pan+"\t"+"\t"+name+"\t"+taxincome+"\t"+tax);
}

public static void main(String[]args)


{
Employee ob=new Employee();
[Link]();
[Link]();
[Link]();
}
}

Output:
Enter the pan number, name, and taxable income of the employee
654594
Dileep
530000
Pan number Name Taxable Income Tax
654594 Dileep 530000.0 16000.0
Program 14
//To find the fine paid in the library
import [Link].*;
class Library
{
double fine;
String name;
int day;
Library()
{
name="";
day=0;
fine=0.0;
}

void input()
{
Scanner in=new Scanner([Link]);
[Link]("Enter the name of the book and number of days");
name=[Link]();
day=[Link]();
}

void cal()
{
if(day<=7)
fine=0.25*day;
else
if(day>=8&&day<=15)
fine=0.4*day;
else
if(day>=16&&day<=30)
fine=0.6*day;
else
if(day>30)
fine=0.8*day;
}

void display()
{
[Link]("The name of the book is "+name+" And fine to be paid is "
+fine);
}

public static void main(String[]args)


{
Library ob=new Library();
[Link]();
[Link]();
[Link]();
}
}

Output:
Enter the name of the book and number of days
Wings of Fire
26
The name of the book is Wings of Fire And fine to be paid is 15.6
Program 15
//To search a number in an array by using linear search
import [Link].*;
class Linear_search
{
public static void main(String[]args)
{
int a[]=new int[10];
int i,num,f=0;
Scanner in=new Scanner([Link]);
[Link]("Enter 10 numbers");
for(i=0;i<10;i++)
{
a[i]=[Link]();
}
[Link]("Enter a number to be search");
num=[Link]();
for(i=0;i<10;i++)
{
if(num==a[i])
{
f=1;
break;
}
else;
}
if(f==1)
[Link]("Number is found at "+(i+1)+"th"+" position");
else
[Link]("Number is not found");
}
}
Output:
Enter 10 numbers
3
5
6
8
9
12
17
19
25
29
Enter a number to be search
12
Number is found at 6th position
Program 16
//To search a number in an array by using binary search
import [Link].*;
class Binary_search
{
public static void main(String[]args)
{
int a[]=new int[10];
int l=0,u=9,mid=0,f=0,num,i;
Scanner in=new Scanner([Link]);
[Link]("Enter 10 numbers in ascending order");
for(i=0;i<10;i++)
{
a[i]=[Link]();
}
[Link]("Enter the number to be search");
num=[Link]();
while(l<=u)
{
mid=(l+u)/2;
if(a[mid]==num)
{
f=1;
break;
}
else
if(a[mid]<num)
l=mid+1;
else
if(a[mid]>num)
u=mid-1;
}
if(f==1)
[Link]("The number is found at "+(mid+1)+"th"+" position");
else
[Link]("The number is not found");
}
}

Output:
Enter 10 numbers in ascending order
25
29
35
36
37
38
39
40
41
43
Enter the number to be search
43
The number is found at 10th position
Program 17
//To sort elements in ascending order using bubble sort technique
import [Link].*;
class Bubble_sort
{
public static void main(String[]args)
{
int i,j,t=0;
int a[]=new int[10];
Scanner in=new Scanner([Link]);
[Link]("Enter 10 numbers");
for(i=0;i<10;i++)
{
a[i]=[Link]();
}
for(i=0;i<9;i++)
{
for(j=0;j<9-i;j++)
{
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
else;
}
}
[Link]("Sorted array");
for(i=0;i<10;i++)
{
[Link](a[i]);
}
}
}

Output:
Enter 10 numbers
12
48
52
96
64
57
36
29
48
72
Sorted array
12
29
36
48
48
52
57
64
72
96
Program 18
// To sort names in alphabetic order using exchange selection sort technique
import [Link].*;
class Exchange_selection
{
public static void main(String[]args)
{
int i,j,pos=0;
String name[]=new String[10];
String t="";
Scanner in=new Scanner([Link]);
[Link]("Enter 10 names");
for(i=0;i<10;i++)
{
name[i]=[Link]();
}
for(i=0;i<9;i++)
{
pos=i;
for(j=i+1;j<10;j++)
{
if(name[j].compareTo(name[pos])<0)
{
pos=j;
}
}
t=name[pos];
name[pos]=name[i];
name[i]=t;
}
[Link]("Sorted in alphabetic order");
for(i=0;i<10;i++)
[Link](name[i]);
}
}

Output:
Enter 10 names
computer
monitor
speaker
mouse
keyboard
printer
scanner
adapter
display
working
Sorted in alphabetic order
adapter
computer
display
keyboard
monitor
mouse
printer
scanner
speaker
working
Program 19
//To display the daily sale of each shop
import [Link].*;
class Super_market
{
public static void main(String[]args)
{
int i,j,f=0,s=0,sale=0;
int a[][]=new int[2][3];
Scanner in=new Scanner([Link]);
[Link]("Enter the daily sale of each shop into the matrix");
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
a[i][j]=[Link]();
}
}
[Link]("The original matrix");
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
[Link](a[i][j]+" ");
}
[Link]();
}
[Link]("Enter the floor number from 0 to 1 and shop number 0 to 2");
f=[Link]();
s=[Link]();
sale= a[f][s];
[Link]("The daily sale of "+(f+1)+" floor and "+(s+1)+" shop is "+sale);
}
}

Output:
Enter the daily sale of each shop into the matrix
20000
15000
18000
22000
14000
17500
The original matrix
20000 15000 18000
22000 14000 17500
Enter the floor number from 0 to 1 and shop number 0 to 2
1
2
The daily sale of 2 floor and 3 shop is 17500
Program 20
//To find the Transpose of a Matrix
import [Link].*;
class Transpose
{
public static void main(String[]args)
{
int i,j;
int a[][]=new int[4][4];
int t[][]=new int[4][4];
Scanner in=new Scanner([Link]);
[Link]("Enter the elements into the matrix");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
a[i][j]=[Link]();
}
}
[Link]("The original matrix");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
[Link](a[i][j]+" ");
}
[Link]();
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
t[j][i]=a[i][j];
}
}
[Link]("The transpose of the matrix is ");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
[Link](t[i][j]+" ");
}
[Link]();
}
}
}

Output:
Enter the elements into the matrix
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
The original matrix
10 12 14 16
18 20 22 24
26 28 30 32
34 36 38 40
The transpose of the matrix is
10 18 26 34
12 20 28 36
14 22 30 38
16 24 32 40

Program 1 
// To find the grade obtained by the student in three subjects 
import java.util.*; 
class Student 
{ 
    public
System.out.println("The grade is C"); 
        else 
        if(aver>40) 
            System.out.println("The stu
Program 2 
//To find the roots of the quadratic equation 
import java.util.*; 
class Quadratic  
{ 
    public static void ma
Output: 
Enter the value of a,b and c 
1 
-8 
12 
The roots are 10.0and 6.0
Program 3 
// To check whether the number is a Sum-product number or not 
import java.util.*; 
class Sum_product 
{ 
    publ
Program 4 
//To print the pattern 
import java.util.*; 
class Pattern_1 
{ 
    public static void main(String[]args) 
    {
Program 5 
//To print the pattern 
class Pattern_2 
{ 
    public static void main(String[]args) 
    { 
        int i,j,a,p=
Program 6 
//To generate the series 
import java.util.*; 
class Series1 
{ 
    public static void main(String[]args) 
    {
Program 7 
//To generate the series 
import java.util.*; 
class Series2 
{ 
    public static void main(String[]args) 
    {
Program 8 
//To whether the number is an Armstrong number or not 
import java.util.*; 
class Armstrong_number 
{ 
    public

You might also like