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];
            }
        }
    }
}

       

Comments

Popular posts from this blog

Sort Boundary Elements Of A Matrix

Lucky Number In Java ISC

Program to fill a square matrix of size ‘n*n” in a circular fashion (clockwise) with natural numbers from 1 to n*n, taking ‘n’ as input.