Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

first and last digit sum java

public class Main {
    public static void main(String[] args) {
        System.out.println(sumFirstAndLastDigit(1221)); 
        // output is 2
    }
    
    public static int sumFirstAndLastDigit (int number) {
        if (number < 0) {
            return -1;
        }
        int lastDigit = number % 10;
        while (number > 9) {
            number /= 10;
        }
        return lastDigit + number;
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: install java centos 8 
Java :: shift elements in array java 
Java :: check if jcheckbox is checked java 
Java :: How to efficiently find the index of smallest value that is larger than some target within a sorted array, in Java? 
Java :: groovy string to json 
Java :: how to find a specific word in a text file in java 
Java :: how to iterate hashset in java 8 
Java :: java random string 
Java :: retrofit dependencies in android studio kotlin 
Java :: what is the difference between sc.nextLine() and sc.next() in java 
Java :: testException = com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field 
Java :: parallel sorting in java 8 
Java :: bukkit scheduled task 
Java :: date java format 
Java :: how-to-check-internet-connection-in-android 
Java :: using buidfeatures to enable viewbinding 
Java :: java csv 
Java :: Display double in decimal places java 
Java :: java init arraylist string 
Java :: convert int array to Integer list java 
Java :: minecraft chunk size 
Java :: java first day of week 
Java :: rps java 
Java :: data java 
Java :: copy arraylist java 
Java :: java print hex format 
Java :: what is java plug-in 
Java :: android java get current time 
Java :: min priority queue in java 
Java :: java split string 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =