Isc Computer Practical Project File
Isc Computer Practical Project File
Isc Computer Practical Project File
START.
Call function void input() to input 2 numbers.
Call a function void display() and read two numbers m, n.
If m>n then print INVALID INPUT: GOTO End.
else run a loop from im to n.
Call boolean isComposite(i) and check true.
Call boolean isMagic(i) and check true.
If true then print i: ff+1.
End loop.
Print the frequency, f.
End.
1:
2:
3:
4:
5:
c0.
Run a loop from i1 to n.
If n%i=0 then cc+1.
End loop.
If c>2 then return true else return false.
1:
2:
3:
4:
5:
1:
2:
3:
4:
5:
6:
s0.
Run a loop till n!=0.
ss+n%10.
nn/10.
End loop.
return s.
DOCUMENTATION
import java.util.Scanner;
import java.io.*;
class CompositeMagic
{ int m,n;
CompositeMagic()
{ m=0;
n=0;
}
public void input()
{ Scanner sc=new Scanner(System.in);
System.out.println("Enter m and n");
m=sc.nextInt();
n=sc.nextInt();
}
public void display()
{ if(m<n)
{ int f=0;
System.out.print("THE COMPOSITE MAGIC INTEGERS ARE: ");
for(int i=m;i<=n;i++)
{ if(isComposite(i)==true && isMagic(i)==true)
{
System.out.print(i+" ");
f++;
} }
if(f>0)
System.out.println("\nFREQUENCY OF COMPOSITE MAGIC INTEGERS IS: "+f);
else
{ System.out.println("Nil");
System.out.println("FREQUENCY OF COMPOSITE MAGIC INTEGERS IS: "+0);
else
System.out.println("INVALID INPUT");
}
public boolean isComposite(int n)
{ int c=0;
for(int i=1;i<=n;i++)
if(n%i==0)
c++;
if(c>2)
return true;
else
return false;
}
public boolean isMagic(int n)
{ int sum=sumDig(n);
while(sum>9)
sum=sumDig(sum);
if(sum==1)
return true;
else
return false;
}
public int sumDig(int n)
{ int sum=0;
while(n!=0)
{ sum=sum+n%10;
n=n/10;
}
return sum;
}
public static void main(String args[])
{ CompositeMagic obj=new CompositeMagic();
obj.input();
obj.display();
}
}
}}
VARIABLE
NAME
DATATYPE
DESCRIPTION
int
int
int
int
int
sum
int
obj
CompositeMa
gic
INPUT
Enter m and n
1
100
OUTPUT
THE COMPOSITE MAGIC INTEGERS ARE: 10 28 46 55 64 82 91 100
FREQUENCY OF COMPOSITE MAGIC INTEGERS IS: 8
INPUT
Enter m and n
1
9
OUTPUT
THE COMPOSITE MAGIC INTEGERS ARE: Nil
FREQUENCY OF COMPOSITE MAGIC INTEGERS IS: 0
INPUT
Enter m and n
100
1
OUTPUT
INVALID INPUT
1:
2:
3:
4:
START.
Call function void input() to input 2 numbers.
Call a function void compute() and read two numbers M, N.
if ((M>=100&&M<=10000)&&(N>=0&&N<100)) then GOTO Step 5 , else GOTO Step
7.
1:
2:
3:
4:
5:
s0.
Run a loop till n!=0.
s s+(n%10)
End loop.
return s.
1:
2:
3:
4:
5:
c0.
Run a loop till n!=0.
cc+1.
nn%10.
return c.
DOCUMENTATION
import java.util.Scanner;
import java.io.*;
class Program
{ long M,N;
Program()
{ M=0;
N=0; }
public void input()
{ Scanner sc=new Scanner(System.in);
System.out.println("Enter M and N");
M=sc.nextLong();
N=sc.nextLong();
}
public void compute()
{ if((M>=100&&M<=10000)&&(N>=0&&N<100))
for(long i=M;;i++)
{ if(sum(i)==N)
{ System.out.println("THE REQUIRED NUMBER : "+i);
System.out.println("TOTAL NUMBER OF DIGITS= "+count(i));
break;
}
}
else
System.out.println("INVALID INPUT");
}
public long sum(long n)
{ long s=0;
while(n!=0)
{ s=s+(n%10);
n=n/10;
}
return s;
}
public int count(long n)
{ int c=0;
while(n!=0)
{ c++;
n=n/10;
}
return c;
}
public static void main(String args[])
{ Program obj=new Program();
obj.input();
obj.compute();
}
}
VARIABLE
NAME
DATATYPE
long
long
long
long
int
obj
Program
INPUT
Enter M and N
100
11
OUTPUT
THE REQUIRED NUMBER : 119
TOTAL NUMBER OF DIGITS= 3
INPUT
Enter M and N
1500
25
OUTPUT
THE REQUIRED NUMBER : 1699
TOTAL NUMBER OF DIGITS= 4
INPUT
Enter M and N
99
11
OUTPUT
INVALID INPUT
DESCRIPTION
1:
2:
3:
4:
5:
START.
Read a number n.
Create a class object, obj.
Call a function void display().
End.
1:
2:
3:
4:
5:
6:
7:
8:
DOCUMENTATION
import java.util.Scanner;
import java.io.*;
class ConsecutiveCombinations
{
int N;
ConsecutiveCombinations(int n)
{
N=n;
}
public void display()
{
int sum=0,j=0;
int c=0;
if(N>=0)
{
for(int i=1;i<N;i++)
{
sum=i;
j=i+1;
while(sum<N)
{
sum=sum+j;
j++;
}
if(sum==N)
{
for(int k=i;k<j;k++)
{
if(k==i)
System.out.print(k);
else
System.out.print(" + "+k);
}
System.out.println();
c++;
}
}
if(c==0)
System.out.println("There are no Consecutive combinations of "+N);
}
else
System.out.println("INVALID INPUT");
}
public static void main(String args[])throws IOException
{
Scanner sc =new Scanner(System.in);
System.out.print("Enter a number: ");
int n=sc.nextInt();
ConsecutiveCombinations obj=new ConsecutiveCombinations(n);
obj.display();
}
}
VARIABLE
NAME
DATATYPE
int
DESCRIPTION
stores a number inputted by the user.
int
stores a number.
sum
int
int
int
int
obj
ConsecutiveCombin
ations
INPUT
Enter a number: 15
OUTPUT
1+2+3+4+5
4+5+6
7+8
INPUT
Enter a number: 100
OUTPUT
9 + 10 + 11 + 12 + 13 + 14 + 15 + 16
18 + 19 + 20 + 21 + 22
INPUT
Enter a number: 4
OUTPUT
There are no Consecutive combinations of 4
INPUT
Enter a number: -10
OUTPUT
INVALID INPUT
ALGORITHMS
Algorithm for void main()
Step
Step
Step
Step
1:
2:
3:
4:
START.
Create a class object, obj.
Call a function void accept().
End.
Step
Step
Step
Step
Step
4:
5:
6:
7:
8:
1:
2:
3:
4:
5:
6:
7:
8:
DOCUMENTATION
import java.util.Scanner;
import java.io.*;
class Date
{ int xday,xmonth,xyear;
String day1;
int M[]={31,28,31,30,31,30,31,31,30,31,30,31};
String D[]={"MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY","SUNDAY"};
Date()
{ xday=0;xmonth=0;xyear=0;
day1="";
}
public void accept()
{ Scanner sc=new Scanner(System.in);
System.out.print("Enter the required date in this format_(dd mm yyyy) :- ");
xday=sc.nextInt();
xmonth=sc.nextInt();
xyear=sc.nextInt();
int flag=0;
if(xday>=1&&xday<=31 && xmonth>=1&&xmonth<=12 && xyear>=1000&&xyear<=9999)
{ if((xmonth==2&&xyear%4==0&& !(xday>=1&&xday<=29)) || (xmonth==2&&xyear%4!=0&& !
(xday>=1&&xday<=28)))
{ System.out.println("INVALID INPUT");
System.exit(0);
}
System.out.print("Enter the first date of year "+xyear+" : ");
day1=sc.next();
for(int i=0;i<7;i++)
{ if(D[i].equalsIgnoreCase(day1))
{ flag=1;
break;
}
}
if(flag==1)
compute();
else
System.out.println("INVALID INPUT");
}
else
System.out.println("INVALID INPUT");
}
public void compute()
{
if(xyear%4==0)
M[1]=29;
int pos=0;
for(int i=0;i<7;i++)
{ if(D[i].equalsIgnoreCase(day1))
{ pos=i;
break;
}
}
int sumOfDays=0;
for(int i=0;i<xmonth-1;i++)
sumOfDays+=M[i];
sumOfDays+=xday-1;
int index=((sumOfDays%7)+pos)%7;
System.out.println(xday+"/"+xmonth+"/"+xyear+" is on "+D[index]);
}
public static void main(String args[])
{ Date obj=new Date();
obj.accept();
}
}
VARIABLE
NAME
DATATYPE
DESCRIPTION
xday
int
xmonth
int
xyear
int
day1
String
M[]
int
D[]
String
flag
int
int
a loop variable.
pos
int
sumOfDays
int
index
int
obj
Date
INPUT
Enter the required date in this format_(dd mm yyyy) :- 19 05 2015
Enter the first date of year 2015 : THURSDAY
OUTPUT
19/5/2015 is on Tuesday
INPUT
Enter the required date in this format_(dd mm yyyy) :- 07 12 1996
Enter the first date of year 1996 : MONDAY
OUTPUT
7/12/1996 is on SATURDAY
INPUT
Enter the required date in this format_(dd mm yyyy) :- 29 02 2016
Enter the first date of year 2016 : FRIDAY
OUTPUT
29/2/2016 is on MONDAY
INPUT
Enter the required date in this format_(dd mm yyyy) :- 29 02 2015
OUTPUT
INVALID INPUT
ALGORITHMS
Algorithm for void main()
Step
Step
Step
Step
Step
1:
2:
3:
4:
5:
START.
Create a class object, obj.
Call a function void accept().
Call a function void isHappy().
End.
DOCUMENTATION
import java.util.Scanner;
import java.io.*;
class Happy
{
int n;
Happy()
{
n=0;
}
public void accept()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter any number: ");
n=sc.nextInt();
}
public void isHappy()
{
int a=sum_sq_digits(n);
while(a>9)
a=sum_sq_digits(a);
if(a==1)
System.out.println("HAPPY NUMBER");
else
System.out.println("NOT A HAPPY NUMBER");
}
public int sum_sq_digits(int x)
{
if(x==0)
return 0;
else
{
int d=x%10;
return (d*d+ sum_sq_digits(x/10));
}
}
public static void main(String args[])
{
Happy obj=new Happy();
obj.accept();
obj.isHappy();
}
}
VARIABLE
NAME
DATATYPE
DESCRIPTION
int
int
int
stores a number.
int
obj
Happy
INPUT
Enter any number: 28
OUTPUT
HAPPY NUMBER
INPUT
Enter any number: 64
OUTPUT
NOT A HAPPY NUMBER
INPUT
Enter any number: 68
OUTPUT
HAPPY NUMBER
Step
Step
Step
Step
Step
1:
2:
3:
4:
5:
START.
Read a String ss.
Create a class object, obj.
Call a function void check().
End.
ls.length().
sum0, k10, flag1.
If l=10 then run a for loop from i0 till l-1 , else GOTO Step 11.
abs.charAt(i).
If ab>=48&&ab<=57 then sumsum+k*(ab-48) else flag0.
kk-1 and end for loop.
abs.charAt(l-1).
if ab='X'||ab='x') then sumsum+k*10.
else if ab>=48&&ab<=57 then sumsum+k*(ab-48) else flag0.
else flag0.
if flag=0 then print INVALID INPUT else call a function void display(sum).
DOCUMENTATION
import java.util.Scanner;
import java.io.*;
class ISBN
{ String s;
ISBN(String ss)
{ s=ss;
}
public void check()
{ int l=s.length();
char ab;
int sum=0,k=10;
int flag=1;
if(l==10)
{ for(int i=0;i<l-1;i++)
{ ab=s.charAt(i);
if(ab>=48&&ab<=57)
sum=sum+(k*(ab-48));
else
{ flag=0;
break;
}
k--;
}
ab=s.charAt(l-1);
if(ab=='X'||ab=='x')
sum=sum+(k*10);
else if(ab>=48&&ab<=57)
sum=sum+(k*(ab-48));
else
flag=0;
}
else
flag=0;
if(flag==0)
System.out.println("INVALID INPUT");
else
display(sum);
}
public void display(int sum)
{ if(sum%11==0)
{ System.out.println("Sum of ISBN code= "+sum);
System.out.println("Sum leaves no remainder, so it is a valid ISBN code");
}
else
{ System.out.println("Sum of ISBN code= "+sum);
System.out.println("Sum leaves remainder, so it is not a valid ISBN code");
}
}
public static void main(String args[])
{ Scanner sc=new Scanner(System.in);
System.out.print("Enter a 10 digit code: ");
String ss=sc.nextLine();
ISBN obj=new ISBN(ss);
obj.check();
}
}
VARIABLE
NAME
DATATYPE
DESCRIPTION
String
int
ab
char
stores a character of s.
int
sum
int
flag
int
ss
String
obj
ISBN
INPUT
Enter a 10 digit code: 0201530821
OUTPUT
Sum of ISBN code= 99
Sum leaves no remainder, so it is a valid ISBN code
INPUT
Enter a 10 digit code: 007462542X
OUTPUT
Sum of ISBN code= 176
Sum leaves no remainder, so it is a valid ISBN code
INPUT
Enter a 10 digit code: 0231428031
OUTPUT
Sum of ISBN code= 122
Sum leaves remainder, so it is not a valid ISBN code
INPUT
Enter a 10 digit code: 15054X9454
OUTPUT
INVALID INPUT
Step 4: End.
1:
2:
3:
4:
1:
2:
3:
4:
5:
6:
7:
Run a loop from i0 to n and a nested loop from j0 to n and then M[i][j]0.
If n%2!=0 then GOTO Step 3 else GOTO Step 6.
Run a while loop till k<=n*n and repeat Steps 4,5.
M[i][j]k , kk+1, ii-1, jj+1.
Create a Magic square matrix of even size.
k1.
Run a loop from i0 to n and a nested loop from j0 to n and then M[i][j]k and
kk+1.
Step 8: jn-1.
Step 9: Create a magic square matrix of odd size.
Step 10: Call a function void display().
DOCUMENTATION
import java.util.Scanner;
import java.io.*;
class MagicMatrix
{ int M[][];
int n;
MagicMatrix() { n=0; }
public void accept()
{ Scanner sc=new Scanner(System.in);
System.out.print("Enter the size of the Matrix : ");
n=sc.nextInt();
if(n<1||n>5)
{ System.out.println("Enter a number between 1 to 5 ");
System.exit(0);
}
M=new int[n][n];
compute();
}
public void compute()
{ int i,j,k,t;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
M[i][j] = 0;
if(n%2!=0)
{ i=0;
j = n/2;
k = 1;
while(k<=n*n)
{ M[i][j] = k++;
i--;
j++;
if(i<0 && j>n-1)
{ i = i+2;
j--; }
if(i<0)
i = n-1;
if(j>n-1)
j = 0;
if(M[i][j]>0)
{ i = i+2;
j--; } } }
else
{ k = 1;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
M[i][j] = k++;
j = n-1;
for(i=0; i<n/2; i++)
{ t = M[i][i];
M[i][i] = M[j][j];
M[j][j] = t;
t = M[i][j];
M[i][j] = M[j][i];
M[j][i] = t;
j--;
} }
display(); }
public void display()
{ System.out.println("The Magic Matrix of size "+n+"*"+n+" is:");
for(int i=0;i<n;i++)
{ for(int j=0;j<n;j++)
System.out.print(M[i][j]+ "\t");
System.out.println();
} }
public static void main(String args[])
{ MagicMatrix obj=new MagicMatrix();
obj.accept();
} }
VARIABLE
NAME
DATATYPE
M[][]
int
int
int
int
int
int
obj
MagicMatrix
INPUT
DESCRIPTION
ALGORITHMS
Algorithm for void main()
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
Step 6:
Step 7:
Step 8:
Step 9:
Step 10:
START.
Read a number, size.
If size<2 || size>10 then print "THE MATRIX SIZE IS OUT OF RANGE".
else create a class object, obj.
Call a function void accept().
Call a function void displayOriginal().
Call a function void rotateMatrix().
Call a function void displayRotated().
Call a function void sumOfCorner().
End.
1:
2:
3:
4:
1:
2:
3:
4:
5:
6:
7:
k0.
Run a for loop from i0 to M and repeat Steps 3,4 .
kM-1.
Run a for loop from j0 to M and repeat Steps 5,6 .
B[i][j]A[k][i]
if k>0, kk-1.
End loop.
1:
2:
3:
4:
DOCUMENTATION
import java.util.Scanner;
import java.io.*;
class MatrixRotation
{
int M;
int A[][],B[][];
MatrixRotation(int size)
{ M=size;
A=new int[M][M];
B=new int[M][M];
}
public void accept()
{ Scanner sc=new Scanner(System.in);
System.out.println("Enter elements of the Matrix");
for(int i=0;i<M;i++)
for(int j=0;j<M;j++)
A[i][j]=sc.nextInt();
}
public void displayOriginal()
{ System.out.println("ORIGINAL MATRIX");
for(int i=0;i<M;i++)
{ for(int j=0;j<M;j++)
System.out.print(A[i][j]+" ");
System.out.println();
}
}
public void rotateMatrix()
{ int k=0;
for(int i=0;i<M;i++)
{ k=M-1;
for(int j=0;j<M;j++)
{ B[i][j]=A[k][i];
if(k>0)
k--;
}
}
}
public void displayRotated()
{ System.out.println("MATRIX AFTER ROTATION");
for(int i=0;i<M;i++)
{ for(int j=0;j<M;j++)
System.out.print(B[i][j]+" ");
System.out.println();
}
}
public void sumOfCorner()
{ int sum=A[0][0]+A[0][M-1]+A[M-1][M-1]+A[M-1][0];
System.out.println("Sum of corner elements= "+sum);
}
public static void main(String args[])
{ Scanner sc=new Scanner(System.in);
System.out.print("Enter size of Matrix: ");
int size=sc.nextInt();
if(size<2||size>10)
System.out.println("THE MATRIX SIZE IS OUT OF RANGE");
else
{ MatrixRotation obj=new MatrixRotation(size);
obj.accept();
obj.displayOriginal();
obj.rotateMatrix();
obj.displayRotated();
obj.sumOfCorner();
} }
VARIABLE
NAME
DATATYPE
DESCRIPTION
A[][]
int
B[][]
Int
int
int
int
int
sum
int
obj
MatrixRotatio
n
INPUT
INPUT
Enter size of Matrix: 11
OUTPUT
THE MATRIX SIZE IS OUT OF RANGE
1:
2:
3:
4:
5:
6:
START.
Read a number n.
if n>=0 then create a class object, obj.
Call a function void display().
else print "INVALID INPUT".
End.
Step 2: sumFsumPrimeFact(N).
Step 3: if sumD==sumF then print "SMITH NUMBER".
Step 4: else print "NOT A SMITH NUMBER".
1:
2:
3:
4:
s0.
Run a while loop till n!=0 and repeat Step 3.
ss+n%10. nn/10.
return s.
1:
2:
3:
4:
i2 , s0.
Run a while loop till n>1 and repeat Step 3.
if n%i=0 then ss+sumDig(i) , nn/I else ii+1.
return s.
DOCUMENTATION
import java.util.Scanner;
import java .lang.*;
class SmithNumber
{
int N;
SmithNumber(int n)
{
N=n;
}
public void display()
{
int sumD=sumDig(N);
int sumF=sumPrimeFact(N);
if(sumD==sumF)
System.out.println("SMITH NUMBER");
else
System.out.println("NOT A SMITH NUMBER");
}
public int sumDig(int n)
{
int s=0;
while(n!=0)
{
s=s+(n%10);
n=n/10;
}
return s;
}
VARIABLE
NAME
DATATYPE
int
int
stores a number.
sumD
int
sumF
int
int
int
a loop variable.
obj
SmithNumber
INPUT
Enter a number: 666
OUTPUT
SMITH NUMBER
INPUT
DESCRIPTION
INPUT
Enter a number: 123
OUTPUT
NOT A SMITH NUMBER
INPUT
Enter a number: -10
OUTPUT
INVALID INPUT
1:
2:
3:
4:
5:
6:
7:
8:
START.
Read a number, size.
Create a class object, obj.
Call a function void accept().
Call a function void display_Original().
Call a function void checkSymmetric().
Call a function void compute().
End.
Step 4: else print "THE MATRIX SIZE IS OUT OF RANGE" and exit the program.
1:
2:
3:
4:
1:
2:
3:
4:
5:
flag1.
Run a for loop from i0 to M and a nested loop from j0 to M and repeat Step 3.
if A[i][j]!=A[j][i] then flag0.
if flag=1 then print "THE GIVEN MATRIX IS SYMMETRIC".
else print "THE GIVEN MATRIX IS NOT SYMMETRIC".
1:
2:
3:
4:
5:
5:
sumLD0, sumRD0.
Run a for loop from i0 to M and a nested loop from j0 to M and repeat Steps .
if i=j then sumLDsumLD+A[i][j].
if i+j=M then sumRDsumRD+A[i][j].
Print sumLD.
Print sumRD.
DOCUMENTATION
import java.util.Scanner;
class Symmetric
{ int A[][];
int M;
Symmetric(int size)
{ M=size;
A=new int[M][M];
}
public void accept()
{ if(M>2&&M<10)
{ Scanner sc=new Scanner(System.in);
System.out.println("Enter elements of the Matrix");
for(int i=0;i<M;i++)
{ for(int j=0;j<M;j++)
A[i][j]=sc.nextInt();
}}
else
{ System.out.println("THE MATRIX SIZE IS OUT OF RANGE");
System.exit(0);
}
}
public void display_Original()
{ System.out.println("\nORIGINAL MATRIX");
for(int i=0;i<M;i++)
{ for(int j=0;j<M;j++)
System.out.print(A[i][j]+" ");
System.out.println();}
}
public void checkSymmetric()
{ int flag=1;
for(int i=0;i<M;i++)
{ for(int j=0;j<M;j++)
{ if(A[i][j]!=A[j][i])
{ flag=0;
break; } } }
if(flag==1)
System.out.println("THE GIVEN MATRIX IS SYMMETRIC");
else
System.out.println("THE GIVEN MATRIX IS NOT SYMMETRIC");
}
public void compute()
{ int sumLD=0,sumRD=0;
for(int i=0;i<M;i++)
{ for(int j=0;j<M;j++)
{ if(i==j)
sumLD+=A[i][j];
if((i+j)==M)
sumRD+=A[i][j]; } }
System.out.println("The sum of the left diagonal= "+sumLD);
System.out.println("The sum of the right diagonal= "+sumRD);
}
public static void main(String args[])
{ Scanner sc=new Scanner(System.in);
System.out.print("Enter size of Matrix: ");
int size=sc.nextInt();
Symmetric obj=new Symmetric(size);
obj.accept();
obj.display_Original();
obj.checkSymmetric();
obj.compute();
}
}
VARIABLE
NAME
DATATYPE
A[][]
int
int
int
int
flag
int
sumLD
int
sumRD
int
obj
Symmetric
INPUT
Enter size of Matrix: 3
Enter elements of the Matrix
123245356
OUTPUT
ORIGINAL MATRIX
1 2 3
2 4 5
3 5 6
DESCRIPTION