Posts

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...