Sunday, September 10, 2017

Functions(return)

Challenge: Write a program that displays the dimensions of a letter-size (8.5 × 11 inches) sheet of paper in millimeters. There are 25.4 millimeters per inch.


Solution:
import java.util.*;


class lab2_3{

public static void main(String[]args)
{
System.out.println("Please: enter the dimenssions of your letter");
Scanner in=new Scanner(System.in);
System.out.println("Enter width:");
double width=in.nextDouble();
System.out.println("Enter length:");
double length=in.nextDouble();
double widthMilli=widthMillimeters(width);
double lengthMilli=lengthMillimeters(length);
System.out.printf("The dimensions of the letter in millimeters is: %.2f", widthMilli);




System.out.printf(" by %.2f", lengthMilli);
System.out.print(" millimeters\n");
//Write a program that asks the user for the lengths of a rectangle’s sides.
//Then print the area and the perimeter of the rectangle.
}
public static double widthMillimeters(double w)
{
return w*25.4;
}
public static double lengthMillimeters(double l)
{
return l*25.4;
}
}

No comments:

Post a Comment