I have to find the most left digit in a randomly generated number (for example: 46891 -> 4). No matter what the number is I keep getting zero. Here’s one of the codes I try:
int num1 = (int)((Math.random()*100000)+1);
while((Math.floor(num1/10))>0)
{
num1 = (int)Math.floor(num1/10);
}
System.out.println("Left digit: " + num1);
I tried to use Integer.parseInt, but I got this mistake, obviously: The method parseInt(String) in the type Integer is not applicable for the arguments (int).
What am I doing wrong and how can I make it work?
Thank you!
how about this :