Friday, July 13, 2007

Print the right most digit of a number

Here's some Java for you my beloved fans :)

public class RightMostDigit {
public static void main(String[] args) {
//One way
int myInt = 155;
System.out.println(155%10);
//Another way
int myInt2 = 140;
System.out.println(Integer.toString(myInt2).substring(Integer.toString(myInt2).length()-1));
/* Output:
* 5
* 0
*/
}
}

No comments: