
Concept explainers
6.17 LAB: Max magnitude
Write a method maxMagnitude() with two integer input parameters that returns the largest magnitude value. Use the method in a
Ex: If the inputs are:
5 7the method returns:
7Ex: If the inputs are:
-8 -2the method returns:
-8Note: The method does not just return the largest value, which for -8 -2 would be -2. Though not necessary, you may use the absolute-value built-in math method.
Your program must define and call a method:
public static int maxMagnitude(int userVal1, int userVal2) tested with 5,7 -8,-2, 25,-50
import java.util.Scanner;
public class LabProgram {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number1 = input.nextInt();
int number2 = input.nextInt();
System.out.println(maxMagnitude(number1, number2));
}
public static int maxMagnitude(int number1, int number2){
number1 = Math.abs(number1);
number2 = Math.abs(number2);
if(number1 >= number2)
return number1;
else
return number2;
}
}

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps

- Exercise 4 (java)arrow_forwardNeed help with 8,9, and 10 if possible. Java Codingarrow_forwardFinancial Application:• Write a program that computes future investment value at a given interest rate for aspecified number of months and prints the report shown in the sample output. • Given the annual interest rate, the interest amount earned each month is computedusing the formula: Interest earned = investment amount * annual interest rate /1200 (=months * 100) • Write a method, computeFutureValue, which receives the investment amount, annualinterest rate and number of months as parameters and does the following: o Prints the interest amount earned each month and the new value of theinvestment (hint: use a loop). o Returns the total interest amount earned after the number of months specified bythe user. The main method will:o Ask the user for all input needed to call the computeFutureValue method.o Call computeFutureValueo Print the total interest amount earned by the investment at the end of thenumber of months entered by the user. Sample Program runningEnter the investment…arrow_forward
- Please Solve, Thank You! 3.18.2: Read in a time and print the equivalent military hour. Read in a time such as 3 pm and print the equivalent military hour (such as 15). Validate the input. If the input doesn't start with an integer, print: Error: Not an integer. If the number isn't between 1 and 12, print: Error: The hour must be between 1 and 12. If the suffix isn't "am" or "pm", print: Error: The suffix must be am or pm. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 import java.util.Scanner; public class TimeReader { publicstaticvoidmain(String[] args) { Scannerin=newScanner(System.in); if (/* Your code goes here */) { inthour=in.nextInt(); if (/* Your code goes here */) { Stringsuffix=in.next(); if (/* Your code goes here */) { /* Your code goes here */ //Convert hour to military time import java.util.Scanner; public class TimeReader{ public static void main(String[] args) { Scanner in = new Scanner(System.in); if (/* Your code…arrow_forwardJava Scriptarrow_forwardpublic class utils { * Modify the method below. The method below, myMethod, will be called from a testing function in VPL. * write one line of Java code inside the method that adds one string * to another. It will look something like this: * Assume that 1. String theInput is 2. string mystring is ceorge неllo, пу nane is * we want to update mystring so that it is неllo, пу nane is Ceorge */ public static string mymethod(string theInput){ System.out.println("This method combines two strings."); Systen.out.println("we combined two strings to make mystring); return mystring;arrow_forward
- 35 36 37 /** 38 * B. Complete a method named blackJack(). 39 * The method is given 2 int values, both of which are * greater than 0. Your method should return whichever * value is nearest to 21 without going over. * Return 0 if they both go over. 40 41 42 43 44 * Examples: blackjack(19, 21) -> 21 blackjack(21, 19) -> 21 blackjack(19, 22) -> 19 45 46 47 48 49 @param a the first number @param b the second number * @return the integer value as described 50 51 52 53 public int blackjack(int a, int b) { // Complete the method here X 54 55 56 57arrow_forwardCan you do it in Javaarrow_forwardProgram to compute interest = p * r * t, where p = $10K, rate = 6%, t = 10 years; these values are to be passed from main() Besides main() the program has two methods: one that computes the interest and on that rounds interest to two decimal places public class DisplayInterest public static void main(String[] args) call a method that will do the computation with values for the above variables; with the exception of year, they are double main() displays computed interest after rounding computation method() rounding method() Note:- Please type and execute this java program and also need an output for this java program.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





