7 min read•june 18, 2024
Avanish Gupta
user_sophia9212
Avanish Gupta
user_sophia9212
public static void printRectanglePerimeter(double length, double width) {
System.out.println(2 * (length + width));
}
printRectanglePerimeter(1.5, 2.5);
8.0
, which is the result of the calculation done in the method.printRectanglePerimeter(double length, double width)
printRectanglePerimeter(double width, double length)
printRectanglePerimeter()
method with the following assumptions:public static void printRectanglePerimeter(double length, double width) {
System.out.println(2 * (length + width));
}
public static void printRectanglePerimeter(double side) {
System.out.println(4 * side);
}
public static void printRectanglePerimeter() {
System.out.println(0);
printRectanglePerimeter(2.5)
would print out 10.0
, while a call to just printRectanglePerimeter()
would print out 0
.public void millimetersToInches(double mm)
{
double inches = mm * 0.0393701;
printInInches(mm, inches);
}
public void printInInches(double millimeters, double inches)
{
System.out.print(millimeters + "-->" + inches);
}
millimetersToInches(25.4)
appears in a method in the same class. What is printed as a result of the method call?public void milesToKilometers(double miles)
{
double km = miles * 1.60934;
printInKilometers(miles, km);
}
public void printInKilometers(double miles, double km)
{
System.out.print(miles + "-->" + km);
}
milesToKilometers(1)
appears in a method in the same class. What is printed as a result of the method call?public void fahrenheitToCelsius(double fahrenheit)
{
double celsius = (fahrenheit - 32) * (5.0/9.0);
printInCelsius(fahrenheit, celsius);
}
public void printInCelsius(double fahrenheit, double celsius)
{
System.out.print(fahrenheit + "-->" + celsius);
}
fahrenheitToCelsius(32)
appears in a method in the same class. What is printed as a result of the method call?public void poundsToKilograms(double pounds)
{
double kilograms = pounds * 0.453592;
printInKilograms(pounds, kilograms);
}
public void printInKilograms(double pounds, double kilograms)
{
System.out.print(pounds + "-->" + kilograms);
}
poundsToKilograms(2)
appears in a method in the same class. What is printed as a result of the method call?public void litersToGallons(double liters)
{
double gallons = liters * 0.264172;
printInGallons(liters, gallons);
}
public void printInGallons(double liters, double gallons)
{
System.out.print(liters + "-->" + gallons);
}
litersToGallons(3.785)
appears in a method in the same class. What is printed as a result of the method call?public void calculateArea(int length, int width)
{
int rectangleArea = length * width;
/* INSERT CODE HERE */
}
public void printArea(int area)
{
System.out.println("The area is: " + area);
}
/* INSERT CODE HERE */
in the method calculateArea
in order to call the printArea
method to print the area correctly?public void calculateSum(int num1, int num2)
{
int numSum = num1 + num2;
/* INSERT CODE HERE */
}
public void printSum(int sum)
{
System.out.println("The sum is: " + sum);
}
/* INSERT CODE HERE */
in the method calculateSum
in order to call the printSum
method to print the sum correctly?public void calculateAverage(int num1, int num2, int num3)
{
int numAverage = (num1 + num2 + num3) / 3;
/* INSERT CODE HERE */
}
public void printAverage(int average)
{
System.out.println("The average is: " + average);
}
/* INSERT CODE HERE */
in the method calculateAverage
in order to call the printAverage
method to print the average correctly?public void calculateDiscount(int price, int discount)
{
int calculatedPrice = price - (price * discount / 100);
/* INSERT CODE HERE */
}
public void printDiscountedPrice(int discountedPrice)
{
System.out.println("The discounted price is: " + discountedPrice);
}
/* INSERT CODE HERE */
in the method calculateDiscount
in order to call the printDiscountedPrice
method to print the discounted price correctly?public void calculateVolume(int length, int width, int height)
{
int boxVolume = length * width * height;
/* INSERT CODE HERE */
}
public void printVolume(int volume)
{
System.out.println("The volume is: " + volume);
}
/* INSERT CODE HERE */
in the method calculateVolume
in order to call the printVolume
method to print the volume correctly?public class MethodTrace
{
public void add(int x, int y)
{
System.out.println(x+y);
}
public void subtract(int x, int y)
{
System.out.println(x-y);
}
public static void main(String[] args) {
MethodTrace traceObj = new MethodTrace();
traceObj.add(5, 3);
System.out.print(" and ");
traceObj.subtract(5, 3);
}
}
public class MethodTrace
{
public void concatenate(String x, String y)
{
System.out.println(x+y);
}
public void repeat(String x, int y)
{
for(int i=0; i<y; i++) {
System.out.print(x);
}
}
public static void main(String[] args) {
MethodTrace traceObj = new MethodTrace();
traceObj.concatenate("Hello", "World");
System.out.print(" and ");
traceObj.repeat("Hello", 3);
}
}
public class MethodTrace
{
public void add(int x, int y)
{
System.out.print(x+y);
}
public void divide(int x, int y)
{
System.out.println(x/y);
}
public static void main(String[] args) {
MethodTrace traceObj = new MethodTrace();
traceObj.add(4, 2);
System.out.print(" and ");
traceObj.divide(5, 2);
}
}
public class MethodTrace
{
public void concatenate(String x, String y)
{
System.out.print(x+y);
}
public void toUpperCase(String x)
{
System.out.println(x.toUpperCase());
}
public static void main(String[] args) {
MethodTrace traceObj = new MethodTrace();
traceObj.concatenate("good", "bye");
System.out.print(" and ");
traceObj.toUpperCase("see you later");
}
}
© 2024 Fiveable Inc. All rights reserved.