Posts

Showing posts with the label Especially For ISC Students

Implementing Queue In Java

import java.util.*; class arrayQueue {     protected int Queue[] ;     protected int front, rear, size, len;     //Constructor     public arrayQueue(int n)     {         size = n;         len = 0;         Queue = new int[size];         front = -1;         rear = -1;     }       //Function to check if queue is empty     public boolean isEmpty()     {         return front == -1;     }       //Function to check if queue is full     public boolean isFull()     {         return front==0 && rear == size -1 ;     }       //Function to get the size of the queue     public int getSize()     {         return len ;  ...

Anagrams In Java ISC ICSE CBSE Class 12

import java.util.*; class Anagram{     public static void main(){         String s;         Scanner sc=new Scanner(System.in);         System.out.println("Enter a word");         s=sc.next();         Anagram ob=new Anagram();         ob.display("",s);     }     public void display(String p,String w){         if(w.length()<=1)         System.out.println(p+w);         else{             for(int i=0;i<w.length();i++){             String a=w.substring(i,i+1);             String b=w.substring(0,i);             String c=w.substring(i+1);             display(p+a,b+c);         }     } ...

Encoding In Java ISC CBSE Class 12

import java.util.*; class Encode{     public static void main(){         Scanner sc=new Scanner(System.in);         String s,t="",str="",p;         int c,k,l;         System.out.println("Enter the code");         s=sc.next();         l=s.length();         if(l>200){             System.out.println("Invalid Code");             return;         }         for(int i=l-1;i>=0;i--){             c=s.charAt(i)-48;             c=9-c;             t=t+Integer.toString(c);         }         for(int j=0;j<=l;j+=2){             p=t.substring(j,j+2);       ...

Decoding In Java ISC CBSE Class 12

import java.util.*; class Decode{     public static void main(){         Scanner sc=new Scanner(System.in);         String str,s="";         int i,l,j,ss,r,sr=0;         System.out.println("Enter a sentence");         str=sc.nextLine();         l=str.length();         for(j=0;j<l;j++){                 if((str.charAt(j)>=65&&str.charAt(j)<=90)||(str.charAt(j)>=97&&str.charAt(j)<=122)||(str.charAt(j)==32)){                    s=s+(int)str.charAt(j);                 }//if             }//for j             ss=Integer.parseInt(s);             while(ss>0){       ...

Denomination Of Notes Currency In Java Isc Icse CBSE

import java.util.*; class Denomination{     public static void main(){      Scanner sc=new Scanner(System.in);      int n,nn,c=0,s=0,i;      int a[]={1000,500,100,50,20,10,5,2,1};         System.out.println("Enter a multidigit no.");          n=sc.nextInt();          nn=n;          if((n+"").length()>5){              System.exit(1);             }             else{             for(i=0;i<=8;i++){                 c=n/a[i];                 if(c!=0){                 System.out.println(a[i]+"  *  "+c+"      "+a[i]*c);           ...

Integer To Roman In Java ISC CBSE Class 12

class Roman{     public void accept(int n){      int c=0,i,j;      int a[]={1000,900,500,400,100,90,50,40,10,9,5,4,1};      String aa[]={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};          if(n>9999){              System.exit(1);             }             else{             for(i=0;i<=12;i++){                 c=n/a[i];                 if(c!=0){                 for(j=1;j<=c;j++)                 System.out.print(aa[i]);             }                 n=n%a[i];             }     ...

Transpose Matrix In Java

//Transpose Matrix import java.util.*; class Matrix{     public static void main (){         Scanner sc=new Scanner(System.in);         int i,j,N;         System.out.println("Enter the value of N");         N=sc.nextInt();         int a[][]=new int[N][N];         for(i=0;i<N;i++){         for (j=0;j<N;j++){         System.out.println("Enter any number");         a[i][j]=sc.nextInt();     }}     for(i=0;i<N;i++){         for (j=0;j<N;j++){     System.out.print(a[i][j]); }System.out.println(); } } }

Magic Square In Java

import java.util.*; class MagicSquare{     public static void main(){         Scanner sc=new Scanner(System.in);         int n,x,i,j;         System.out.println("Enter size of an array");         n=sc.nextInt();         int a[][]=new int[n][n];         i=0;         j=(n-1)/2;         x=1;         do{             if(a[i][j]!=0){                 i=(i+2)%n;                 j=(j+1)%n;             }//end of if             a[i][j]=x++;             i--;             j--;             if(i<0)           ...

Delete Duplicate Elements In Java

import java.util.*; class Duplicate{     public int length1(int y[]){         int l,i,k,c=0,j;         l=y.length;         for(i=0;i<l;i++){         for(j=0;j<l;j++){             if(y[i]==y[j]){                 if(i<=j){                     c++;                     break;                 }//if                 else                 break;             }//if         }//for j     }//for i     return c; }//method public static void main(){   Scanner sc=new Scanner(System.in);   int i,j;   int a[]=new int[...

Decimal To Hexadecimal In Java

//DECIMAL TO HEXADECIMAL class Dec2Hex{     public void convert(int d){         char c=' ';         String s="";         int r;         while(d!=0){             r=d%16;             d=d/16;             if(r<10)             c=r>10?(char)(r+55):(char)(r+48);             s=c+s;         }         System.out.println(s);     }}         

Days To Date In Java

//DAYS TO DATE class daystodate{     private int a[]={31,28,31,30,31,30,31,31,30,31,30,31};     public void convert(int d,int y){         int m;         if(y%100!=0&&y%400==0||y%4==0)         a[1]=29;         else         a[0]=28;         for(m=0;d>a[m];m++){             d=d-a[m];         }         System.out.println("THE CORRECT DATE IS = "+d+"/"+(m+1)+"/"+y);     }}         

Date To Days In Java

//DATE TO DAYS class datetodays{     private int a[]={31,28,31,30,31,30,31,31,30,31,30,31};     public void convert(String str){         int d,m,y,i,s=0;         if(str.indexOf('/')!=2||str.lastIndexOf('/')!=5||str.length()!=10){             System.out.println("Invalid Date");             return;         }         d=Integer.parseInt(str.substring(0,2));         m=Integer.parseInt(str.substring(3,5));         y=Integer.parseInt(str.substring(6));         if(y%100!=0&&y%400==0||y%4==0)         a[1]=29;         else         a[1]=28;         s=d;         for(i=0;i<m-1;i++)         s=s+a[i];         System.o...

Vampire Number In Java

class Vampire{     public void check(){         int i,t;         for(i=1000;i<=9999;i++){             if(isvampire(i)==true)             System.out.println(i);         }}         private boolean isvampire(int n){             int i,j,l,k,x,y;             boolean b=false;             String s=""+n;             for(i=0;i<4;i++){                 for(j=0;j<4;j++){                     if(i==j)                     continue;                     for(k=0;k<4;k++){               ...

Check Date Valid In Java

//ACCEPT A DATE IN THE FORM DD/MM/YYYY AND CHECK IT IS VALID OR NOT import java.util.*; class CheckDate{     private String str;     private int m[]={31,28,31,30,31,30,31,31,30,31,30,31};     public void check(String str){         if(str.indexOf('/')!=2||str.lastIndexOf('/')!=5||str.length()!=10){             System.out.println("Invalid Date");             return;         }         int dd,mm,yy;         dd=Integer.parseInt(str.substring(0,2));         mm=Integer.parseInt(str.substring(3,5));         yy=Integer.parseInt(str.substring(6));         {if(yy%100!=0&&yy%400==0||yy%4==0)         m[1]=29;         else         m[1]=28;}         {if((mm>=1&...

Sort Boundary Elements Of A Matrix

ISC COMPUTER SCIENCE PRACTICALS 2009 BOUNDARY ELEMENTS Write a program to declare a matrix A[ ][ ] of order (m*n) where 'm' is the number of rows and n is the number of columns such that both m and n must be greater than 2 and less than 20. Allow the user to input positive integers into this matrix. Perform the following tasks on the matrix: (a) Sort the elements of the outer row and column elements in ascending order using any standard sorting technique. (b) Calculate the sum of the outer row and column elements. (c) Output the original matrix, rearranged matrix, and only the boundary elements of the rearranged array with their sum. Test your program for the following data and some random data. 1. Example : INPUT : M=3, N=3 1 7 4 8 2 5 6 3 9 OUTPUT : ORIGINAL MATRIX : 1 7 4 8 2 5 6 3 9 REARRANGED MATRIX : 1 3 4 9 2 5 8 7 6 BOUNDARY ELEMENTS : 1 3 9 8   4 5 7 6 SUM OF OUTER ROW AND OUTER COLUMN = 43     ISC COMPUTER SCIENCE PRACTICALS 2009 ...

Number To Word In Java

//NUMBER TO WORD class Number2Word{     private String a1[]={"Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen","Fourteen","Fiteen","Sixteen","Seventeen","Eighteen","Nineteen"};     private String a2[]={"Twenty","Thirty","Fourty","Fifty","Sixty","Seventy","Eighty","Ninety"};     public void display(int n){         if(n<=19)         f1(n);         else if(n<=99)         f2(n);         else         f3(n);     }     public void f1(int n){         System.out.println(a1[n]);     }     public void f2(int n){         int x,y;         x=n/10;         y=n%10;         if(y==0)         System.out.println(a2[x-2]);...

Recursive program on Tower of Hanoi

Recursive program on Tower of Hanoi. import java.util.*; class TowerHRec {     public static void main(String args[])     {         int n;         char beg='A',aux='B',end='C';         Scanner sc=new Scanner(System.in);         System.out.println("Enter number of disks:");         n=sc.nextInt();         TowerHRec obj=new TowerHRec();         obj.move(n,beg,aux,end);     }     void move(int n,char beg,char aux,char end)     {         if(n==1)           System.out.println("Move "+n+" disks from "+beg+" -> "+end);                   else         {             move(n-1,beg,end,aux);             System.out.printl...

Queue Implement Array

Queue data structure using Array. import java.util.*; class arrayQueue {     protected int Queue[] ;     protected int front, rear, size, len;     //Constructor     public arrayQueue(int n)     {         size = n;         len = 0;         Queue = new int[size];         front = -1;         rear = -1;     }       //Function to check if queue is empty     public boolean isEmpty()     {         return front == -1;     }       //Function to check if queue is full     public boolean isFull()     {         return front==0 && rear == size -1 ;     }       //Function to get the size of the queue     public int getSize()     {    ...

Implement Stack data structure using Array.

Implement Stack data structure using Array. import java.util.*; class Stack1 {     int s[],max,top;     public static void main()     {         int ch,size;         Scanner sc =new Scanner(System.in);         System.out.println("Enter the size of the stack");         size=sc.nextInt();         Stack1 obj=new Stack1();         obj.assign(size);         while(true)         {             System.out.println("1:PUSH\n2:POP\n3:DISPLAY\n4:EXIT");             System.out.println("Enter your choice");             ch=sc.nextInt();             switch(ch)             {                 case 1: System.out.pr...

Evil Number In Java

Write a Program in Java to input a number and display the Evil Numbers from 1 to 50. import java.util.*; class EvilNumber {     String toBinary(int n) // Function to convert a number to Binary     {         int r;         String s="";         char dig[]={'0','1'};         while(n>0)             {                 r=n%2; //finding remainder by dividing the number by 2                 s=dig[r]+s;                 n=n/2;             }         return s;     }//toBinary         int countOne(String s)     {         int c = 0, l = s.length();         char ch;         for(int...