In Java Write a Java program where the main method prompts t

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 \"\\t\" 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
  
}

Solution

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 + \"\\t\" + kilogram);
}
}
}

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 printTa
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 printTa

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site