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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started