Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need Help In Java Need to fix this file that does this: 1. User enters two integers 2. find closest to 21 3. Eliminate if

Need Help In Java

Need to fix this file that does this:

1. User enters two integers

2. find closest to 21

3. Eliminate if over 21

The code that have so far for file:

package week4;

import java.util.Scanner;

public class MathMethods { public static void main(String[] args) {

System.out.println("Hello to all of you users.");

int num1 = getNum(); int num2 = getNum(); int perfectNum=0; boolean num1Equal=checkNumEqual(num1); boolean num2Equal=checkNumEqual(num2); if (num1Equal) { perfectNum=num1; printValue(perfectNum); }else if(num2Equal) { perfectNum=num2; printValue(perfectNum); } int num1Diff=getDiff(num1); int num2Diff=getDiff(num2);

}

public static int getNum() { Scanner input = new Scanner(System.in); System.out.println("Enter a number"); return input.nextInt(); }

public static boolean checkNumEqual(int num) { boolean ans = false; if (num == 21) { ans = true; } return ans; } public static void printValue(int num) { System.out.println("Your number is;"); System.out.println(num); System.exit(0); } public static int getDiff(int num1) { return (21-num1); } public static boolean IsLargerThan21(int num1) { return (21-num1<=0); } public static int getSmaller(int num1, int num2) { return Math.min(num1, num2); }

}

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_2

Step: 3

blur-text-image_3

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

Logic In Databases International Workshop Lid 96 San Miniato Italy July 1 2 1996 Proceedings Lncs 1154

Authors: Dino Pedreschi ,Carlo Zaniolo

1st Edition

3540618147, 978-3540618140

Students also viewed these Databases questions