Hello Programmers, welcome to ozanecare. this article i am going to write codes to calculate sum of first and last digits using java programming language. we can easily achieve the output by using modulus and divide operators. modulus operator return remainder and divide operator return quotient. below image is the codes to find sum of last and first digits.
if you run the program then compiler reach to main method.now that start processing main method block. next user taken integer variable n. System.out.print(“Enter Any Positive Number :”).Enter Any Positive Number : that display into output screen. next n = sc.nextInt() .it is used to read variable into memory. next int sum = fun(n); when compiler reach to fun method. it calls fun method now that reach public static int fun(int num) method. it process fun method.now it back inside Main and it store calculated value in sum and print sum value.