Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Procedures for Lab Labs will be run asynchronously during the week that they are assigned for. You are welcome to work with a partner to

Procedures for Lab
Labs will be run asynchronously during the week that they are assigned for. You are welcome to work with a partner to complete the lab. You can have your progress evaluated after any subset of the milestones are completed. The labs are designed to be able to be completed in about an hour. You have until the end of Friday to get all your milestones checked off (unless you request an extension). The office hours schedule, including locations, is located on Canvas. We suggest you get your milestones checked off as soon as you complete them since Friday office hours tend to become extremely crowded. You will only receive credit for the milestones you have checked off by a TA.
Introduction
Welcome to our third week of CSCI 1933! This lab will introduce the Scanner class and get you more familiar with how arrays work, as well as giving you more practice on recursive and iterative algorithms.
1 Find the Maximum Digit in a Number
In this section, you will find the maximum digit in a given positive int both recursively and iteratively. Write a Max class which will have the following methods:
public static int recursiveMaxDigit(int num)- This will find the maximum digit in num recursively
public static int iterativeMaxDigit(int num)- This will find the maximum digit in num iteratively
Add test cases of both methods into your main method.
Hint: Use integer division [/] and the modulo (remainder) operation [%] to separate out the individual digits. For example, 1634/10=163 and 1634%10=4 using Java logic.
Example Test Cases:
recursiveMaxDigit(578) will return 8
recursiveMaxDigit(10) will return 1
iterativeMaxDigit(9999) will return 9 iterativeMaxDigit(13442) will return 4
1
CSCI 1933 LAB 22. WORKING WITH SCANNER
Milestone 1:
Show a TA your code for recursiveMaxDigit(int) and iterativeMaxDigit(int) and show your test cases running successfully.
2 Working with Scanner
Over the course of this lab, you may have been slightly bothered by how often you are required to recompile. Every time you change your code, even if its just to slightly change, say, the input to your recursiveMaxDigit(int) method youll have to recompile. There is, however, a better way to do this. We can use the Scanner class.
First off, youll need to import the Scanner class. This is what allows you to use the class in your program. To do this, at the very top of your file, even above the public class Max line, you should add this line:
import java.u

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

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

Students also viewed these Databases questions

Question

What is an interval estimator?

Answered: 1 week ago