Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In JAVA using Netbeans Create a method called sumLastValues that will produce th

ID: 3752754 • Letter: I

Question

In JAVA using Netbeans

Create a method called sumLastValues that will produce the sum of the last two values in an int variable. Your method should take as a parameter the integer to extract the last two values from. Your method should check to make sure that the int has at least two digits in it. If it does not your method should simply return-1 If it does extract the last two digits return their sum NOTE You are not allowed to convert the number to a string in any way. You must compute the last two values using the math operators. Example Given the number 123 as input your method should return 5 because the last two digits are 3+ 2 n,MSJC son, MsJC

Explanation / Answer

public class SumLastValues { public static int sumLastValues(int n) { int n1 = n % 10; int n2 = (n / 10) % 10; if(n2 == 0) { return -1; } else { return n1 + n2; } } public static void main(String[] args) { System.out.println(sumLastValues(123)); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote