Question: Java code not working. I have listed my code and i am unsure of why it is working. The goal of this code is to
Java code not working. I have listed my code and i am unsure of why it is working. The goal of this code is to write a program that gets a three-digit integer (99 import java.io.*; import java.lang.*; import java.util.*; import java.util.Scanner; public class ProblemSolution{ static int sum(int n) { int num = 0; if (99 < n) { num = num + n % 10; n = n / 10; } else { System.out.println("-1"); } return num; } public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Please input a 3 digit number to add each digit together"); int n = in.nextInt(); System.out.println(sum(n)); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
