Possible Duplicate:
Decimal Conversion error
I am writing a program for a class and is having trouble figuring how to convert an octal number to an decimal number. Here is what I been trying to do so far:
import java.util.Scanner;
public class test
{
public static void main ( String args[])
{
Scanner input = new Scanner(System.in);
System.out.print("Enter number: ");
int oct = input.nextInt();
int d2count = 0;
int result=0;
int d3count = 0;
int d3 = 0;
int d2 = 0;
d3 = oct;
d2 = oct;
if(oct < 1000){
while ( d3 >= 100){
d3 = d3 - 100;
d3count++;
}}
if (oct < 100){
while ( d2 >= 10){
d2 = d2 - 10;
d2count++;
}}
result = (d3count * 64)+(d2count * 8) + d2;
System.out.printf("%d\n",result);
}
}
so basically I need a way to reduced a number to single digits (ie. 1337 into 1,3,3,7). I would really like to do it with what I have now, but my way of doing seems to have some errors that I can't see. It actually works if I enter a number less then 100, but When I enter a number higher then 100 the conversion is gets messed up somewhere. I am new to java so the more basic the techique the better, thanks