Search
 
SCRIPT & CODE EXAMPLE
 

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);
    }
}
Comment

Find first and last digit of int

#include <iostream>
using namespace std;

int main()
{
    int number;
    cout << "Enter a number : " << endl;
    cin >> number;

    cout << "Last digit is : " << number % 10 << endl;

    while(number >= 10){
        number = number/10;
    }

    cout<< "First digit is : "<< number << endl;
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Java :: hashtable java 
Java :: java map merge example 
Java :: java repeat method 
Java :: java enum 
Java :: how to convert kilometers to miles in java 
Java :: android set focus on edittext 
Java :: java int array to integer arraylist 
Java :: do...while loop Java 
Java :: design custom button in android 
Java :: keytool error: java.lang.Exception: Key pair not generated, alias <demo already exists 
Java :: the main of java 
Java :: initialize an array in java 
Java :: how to add to an arraylist java 
Java :: Cannot find a class with the main method. 
Java :: java.lang.NullPointerException 
Java :: java pattern check 
Java :: fibonacci series in java 
Java :: tableau de chaîne de caractère en java 
Java :: how to create a function in java 
Java :: javafx fxmlloader location is not set 
Java :: convert date to localdate java 
Java :: activityViewModels 
Java :: unchecked exception in java 
Java :: get intersection of two lists java 
Java :: java implement interface 
Java :: Java List Add Elements using add() method 
Java :: remove tableview separator lines in javafx 
Java :: How to merge two sorted arrays in Java? 
Java :: how to create a java library in intellij 
Java :: add infinite values to variable java 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =