0

I have a problem here. I want to try to figure out how to take an integer, let's use 1234, and split into it's "place values." This means changing

1234

into

1000, 200, 30, 4

I am thinking about putting these into arrays, but im not sure what to do from there. My entire code will take any user input and turn it into roman numerals, and this is what i am thinking.

2 Answers2

1

Try the below code

import java.util.*;

public class First
{
    public static void main(String args[])
    {
         Scanner scan = new Scanner(System.in);
         int num = scan.nextInt();
         int i=1,mod;
         while(num>0)
         {
            mod = num % 10;
            System.out.println(mod*i);
            i=i*10;
            num = num/10;
         }
    }
}

This code will print the position value. You could store it in array other purpose.

Tapan Prakash
  • 773
  • 8
  • 7
0

this gives you the expected output, you could add the number to an arry using variable rem, the integer div is number of digits * 10

    int num = 1234;
    int div = (int) Math.pow(10, (int)(Math.log10(num)));
    while(num > 0) {
        int rem = num / div;
        num = num % div;
        div /= 10;
        System.out.println("num : -> "+ rem);
    }
Sudheera
  • 1,727
  • 1
  • 12
  • 28