Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AutoCAD Database Connectivity

Authors: Scott McFarlane

1st Edition

0766816400, 978-0766816404

More Books

Students also viewed these Databases questions