Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
333 views

11th ISC Computer Application Project

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
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
333 views

11th ISC Computer Application Project

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
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Program 1

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


import java.util.*;
class Student
{
public static void main(String[]args)
{
int a,b,c;
double aver=0.0;
Scanner in=new Scanner(System.in);
System.out.println("Enter the marks in three subjects");
a=in.nextInt();
b=in.nextInt();
c=in.nextInt();
aver=(a+b+c)/3;
if(aver>=90)
System.out.println("The grade is A+");
else
if(aver>=80&&aver<90)
System.out.println("The grade is A");
else
if(aver>=70&&aver<80)
System.out.println("The grade is B+");
else
if(aver>=60&&aver<70)
System.out.println("The grade is B");
else
if(aver>=50&&aver<60)
System.out.println("The grade is C+");
else
if(aver>=40&&aver<50)
System.out.println("The grade is C");
else
if(aver>40)
System.out.println("The student got no grade");
System.out.println("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 java.util.*;
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(System.in);
System.out.println("Enter the value of a,b and c");
a=in.nextInt();
b=in.nextInt();
c=in.nextInt();
d=b*b-4*a*c;
if(d>=0)
{
x1=-b+Math.sqrt(d)/(2*a);
x2=-b-Math.sqrt(d)/(2*a);
System.out.println("The roots are "+x1+" and "+x2);
}
else
if(d<0)
System.out.println("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 java.util.*;
class Sum_product
{
public static void main(String[]args)
{
int r,n,m,s=0,p=1;
Scanner in=new Scanner(System.in);
System.out.println("Enter a Number");
n=in.nextInt();
while(n>0)
{
r=n%10;
s=s+r;
p=p*r;
n=n/10;
}
if(s==p)
System.out.println("The number is sum-product");
else
System.out.println("The number is not sum-product");
}
}
Output:
Enter a Number
123
The number is sum-product
Program 4
//To print the pattern
import java.util.*;
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)
{
System.out.print(j);
}
if(i>1)
{
for(k=1;k<=p;k+=2)
{
System.out.print(k);
}
System.out.println();
p=p+2;
}
else
System.out.println();
}
}
}
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++)

System.out.print(i);

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

System.out.print(a);

System.out.println();

p++;

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

Output:
Enter the value of n
6
0 ,7 ,26 ,63 ,124 ,215 ,
Program 7
//To generate the series
import java.util.*;
class Series2
{
public static void main(String[]args)
{
int i,n,s=0;
double l=0.0;
Scanner in=new Scanner(System.in);
System.out.println("Enter the value of n");
n=in.nextInt();
for(i=0;i<=n;i++)
{
s=s*10+5;
l=s/10.0;
System.out.print(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 java.util.*;
class Armstrong_number
{
public static void main(String[]args)
{
int n, r=0,s=0,c=1,m=0;
Scanner in=new Scanner(System.in);
System.out.println("Enter the number");
n=in.nextInt();
m=n;
while(n>0)
{
r=n%10;
c=r*r*r;
s=s+c;
n=n/10;
}
if(s==m)
System.out.println("The number is a Armstrong number");
else
System.out.println("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 java.util.*;
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(System.in);
System.out.println("Enter the sentence");
str=in.nextLine();
str=str.toUpperCase();
StringTokenizer str1=new StringTokenizer(str," .");
while(str1.hasMoreTokens())
{
str2=str1.nextToken();
len=str2.length();
for(i=0;i<len;i++)
{
ch=str2.charAt(i);
if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
{
str3=str2.substring(i,len);
str4=str3+ str2.substring(0,i);
}
else;
}
str5=str5+str4+"AY"+" ";
}
System.out.println("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 java.util.*;
class Sentence
{
public static void main(String[]args)
{
int i,len=0;
String str,str1="",str2="";
char ch;
Scanner in=new Scanner(System.in);
System.out.println("Enter a sentence");
str=in.nextLine();
str=str+" ";
len=str.length();
for(i=0;i<len;i++)
{
ch=str.charAt(i);
if(ch==' ')
{
str2=str2+" "+str1;
str1=" ";
}
else
str1=ch+str1;
}
System.out.println("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 java.util.*;
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(System.in);
System.out.println("Enter any Full Name");
str=in.nextLine();
str=" "+str;
len=str.length();
p=str.lastIndexOf(' ');
str2=str.substring(p+1,len);
for(i=0;i<p;i++)
{
ch=str.charAt(i);
if(ch==' ')
{
ch1=str.charAt(i+1);
str1=str1+ch1+'.';
}
else;
}
str3=str2+" "+str1;
System.out.println("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 java.util.*;
class Menu
{
public static void main(String[]args)
{
int ch,n,i,j;
Scanner in=new Scanner(System.in);
System.out.println("Enter 1 for triangle and 2 for inverted triangle");
ch=in.nextInt();
System.out.println("Enter a number");
n=in.nextInt();
switch(ch)
{
case 1:for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(i);
}
System.out.println();
}
break;
case 2:for(i=n;i>=1;i--)
{
for(j=1;j<=i;j++)
{
System.out.print(i);
}
System.out.println();
}
break;
default:System.out.println("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 java.util.*;
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(System.in);
System.out.println("Enter the pan number, name, and taxable income of the
employee");
pan=in.nextInt();
name=in.next();
taxincome=in.nextDouble();
}

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()
{
System.out.println("Pan number"+"\t"+"Name"+"\t"+"Taxable
Income"+"\t"+"Tax");
System.out.println(pan+"\t"+"\t"+name+"\t"+taxincome+"\t"+tax);
}

public static void main(String[]args)


{
Employee ob=new Employee();
ob.input();
ob.cal();
ob.display();
}
}

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 java.util.*;
class Library
{
double fine;
String name;
int day;
Library()
{
name="";
day=0;
fine=0.0;
}

void input()
{
Scanner in=new Scanner(System.in);
System.out.println("Enter the name of the book and number of days");
name=in.nextLine();
day=in.nextInt();
}

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()
{
System.out.println("The name of the book is "+name+" And fine to be paid is "
+fine);
}

public static void main(String[]args)


{
Library ob=new Library();
ob.input();
ob.cal();
ob.display();
}
}

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 java.util.*;
class Linear_search
{
public static void main(String[]args)
{
int a[]=new int[10];
int i,num,f=0;
Scanner in=new Scanner(System.in);
System.out.println("Enter 10 numbers");
for(i=0;i<10;i++)
{
a[i]=in.nextInt();
}
System.out.println("Enter a number to be search");
num=in.nextInt();
for(i=0;i<10;i++)
{
if(num==a[i])
{
f=1;
break;
}
else;
}
if(f==1)
System.out.println("Number is found at "+(i+1)+"th"+" position");
else
System.out.println("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 java.util.*;
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(System.in);
System.out.println("Enter 10 numbers in ascending order");
for(i=0;i<10;i++)
{
a[i]=in.nextInt();
}
System.out.println("Enter the number to be search");
num=in.nextInt();
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)
System.out.println("The number is found at "+(mid+1)+"th"+" position");
else
System.out.println("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 java.util.*;
class Bubble_sort
{
public static void main(String[]args)
{
int i,j,t=0;
int a[]=new int[10];
Scanner in=new Scanner(System.in);
System.out.println("Enter 10 numbers");
for(i=0;i<10;i++)
{
a[i]=in.nextInt();
}
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;
}
}
System.out.println("Sorted array");
for(i=0;i<10;i++)
{
System.out.println(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 java.util.*;
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(System.in);
System.out.println("Enter 10 names");
for(i=0;i<10;i++)
{
name[i]=in.nextLine();
}
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;
}
System.out.println("Sorted in alphabetic order");
for(i=0;i<10;i++)
System.out.println(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 java.util.*;
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(System.in);
System.out.println("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]=in.nextInt();
}
}
System.out.println("The original matrix");
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println();
}
System.out.println("Enter the floor number from 0 to 1 and shop number 0 to 2");
f=in.nextInt();
s=in.nextInt();
sale= a[f][s];
System.out.println("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 java.util.*;
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(System.in);
System.out.println("Enter the elements into the matrix");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
a[i][j]=in.nextInt();
}
}
System.out.println("The original matrix");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println();
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
t[j][i]=a[i][j];
}
}
System.out.println("The transpose of the matrix is ");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
System.out.print(t[i][j]+" ");
}
System.out.println();
}
}
}

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

You might also like