Question
Define a method showMultiples that takes three int arguments: int lower, int upper, int item, and displays the multiples of the number item in the
Define a method showMultiples that takes three int arguments: int lower, int upper, int item, and displays the multiples of the number item in the range of lower and upper, inclusively. In the main method, call the showMultiples method to output the multiples of 2 in the range of 1 and 100. output the multiples of 3 in the range of -20 and 20. output the multiples of 5 in the range of 1 and 1000.
Define a method named inputGPA that reads from keyboard a floating-point value as a GPA, validates and returns the value. A valid GPA is between 0 and 4.0. If the user input is invalid, asks the user to reenter the value until a valid GPA is entered. In the main method, call the inputGPA method and output the returned GPA value on the screen.
Below is the starter program code in java
public class Lab4 {
public static void main(String[] args) {
double f, c;
System.out.println("Helloooooooooo"); for (f = 0; f <= 104; f += 2) { c = convertCelsius(f); System.out.printf("%.2f \t %.2f ", f, c);
} showMultiples(-20,20,3); }
public static double convertCelsius(double f) {
return (f - 32) * 5 / 9; }
public static void showMultiples(int lower, int upper, int item) {
for (int i = lower; i <= upper; i++) { if (i % item == 0) { System.out.print(i + " "); } }
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