How do i convert a decimal number to octal?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HaifaCarina
    New Member
    • Sep 2007
    • 13

    How do i convert a decimal number to octal?

    Here's the code is used but...but still something is wrong... i need help...

    Code:
    /*CONVERTING DECIMAL TO OCTAL*/
        	String inputDeci,octal="";
        	int deci,count=0, i, h;
        	 
        	
        	inputDeci = JOptionPane.showInputDialog("Enter a decimal number ");
        	deci = Integer.parseInt(inputDeci);
        	
        	int [] quotient = new int [50];
        	int [] remainder = new int [50] ;
        	
        	quotient[0] = deci / 8;
        	remainder[0] = deci % 8;
        	octal+=""+remainder[0];
         	
        	for (i = 0; remainder[0+i] < 8 || quotient[0+i]>= 8; i++){
        		
        		quotient[i+1] = quotient[i] / 8;
        		remainder[i+1] = quotient[i] % 8;	
        		count+=1;
        		System.out.println(remainder[i]);
    
        		
        	}
        	for(h=count;h<0;h--){
        		
        		octal+= ""+ remainder[h];
        		
        	}
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Did you read about the Integer.toStrin g(int number, int radix) method?

    kind regards,

    Jos

    Comment

    Working...