I am exceptionally new to programming, but I am working to improve my programming skills. I am currently working on a problem that I have given myself, where I am trying to take a variable number and make each of its digits a separate number in the array. I donβt care about the order of the numbers, so if they change, then it doesnβt matter to me. I know that people have asked this question many times, but they always seem to use a lot of things that I donβt understand. Since my school does not offer Java courses, I only know what I learned on my own, so if you could explain any terms that you use in code that is not extremely trivial, that would be great. Right now, I wrote:
int number = 1234567890; while (number > 0) { System.out.println(number%10); number = number/10;
This is great for printing numbers individually, but I can't figure out how to add them to the array. I am very grateful for any help you can give, and please keep in mind that I prefer simplicity to small sizes. Thank you in advance!
PS Some of the answers I saw on similar questions include what I consider to be arrays of strings. In order for the part of the program that I was working on to still work, I believe that I need to use an array of integers. If you're interested, the rest of the code is used to determine if the numbers in the array are different, to achieve the final result of determining if the digits of the digits are different. It looks like this:
int repeats=0; int[] digitArray; digitArray = new int[10]; for (int i = 0; i < digitArray.length; i++) for (int j = 0; j < digitArray.length; j++) if ((i != j) && (digitArray[i]==digitArray[j])) unique = unique+1; System.out.println(unique==0);
user2049256
source share