Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Java, Write a Java program where the main() method prompts the user to select

ID: 3940585 • Letter: I

Question

In Java,

Write a Java program where the main() method prompts the user to select an integer value between 1 and 30. Pass that value into a method called printTable().

The printTable() method takes one int type parameter that is used to indicate the number of rows output in the table. Example: printTable(rows);

The printTable() method outputs the table like this

The basic loop can be found on page 43 of our Course Reader. Your method will have only one parameter (essentially the "stop" variable). Use two spaces between "Pounds" and "Kilogram" and a tab character " " between the pounds and kilos variable outputs.

In this format

import java.util.Scanner;

public class Lab6d {
public static void main(String[] args) {
  
Scanner scnr = new Scanner(System.in);
// TODO: get user choice

  
// TODO: call printTable method passing choice as the parameter
  
}

public static void printTable(int stop) {
// TODO: print header
  
// TODO: loop to print table rows up to stop value
  
}

Explanation / Answer

import java.util.Scanner;
public class Lab6d {
public static void main(String[] args) {
  
Scanner scnr = new Scanner(System.in);
// TODO: get user choice
System.out.println("Enter number between 1 to 30");
int choice=scnr.nextInt();
scnr.close();
// TODO: call printTable method passing choice as the parameter
printTable(choice);
}

public static void printTable(int stop) {
// TODO: print header
System.out.println("Pounds Kilograms");

// TODO: loop to print table rows up to stop value
for(int i=1;i<=stop;i++)
{
double kilogram = i*.453;
System.out.println(i + " " + kilogram);
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote