Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

first and last digit of a number in java

public class Main
{  
    public static void main(String args[])
    {  
        int number = 502356997;
        int firstDigit = 0;
        int lastDigit = 0;
 
        lastDigit = number%10;
        System.out.println("Last digit: "+lastDigit);
 
        while(number!=0) {
            firstDigit = number%10;
            number /= 10;
        }
        System.out.println("First digit: "+firstDigit);
    }
}
Source by java2blog.com #
 
PREVIOUS NEXT
Tagged: #digit #number #java
ADD COMMENT
Topic
Name
7+8 =