In: Computer Science
Write by hand a full java program that will prompt the user for the length and width of a square, calculate and display the area of that square rounded to the nearest tenth with an appropriate message.
Java code:
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner s = new
Scanner(System.in);
int length,width;
System.out.print("Enter the length
of a square (cm):");
length = s.nextInt();
System.out.print("Enter the width of a square (cm):");
width = s.nextInt();
int area = length*width;
int temp = area%10;
if(10-temp>5)
area = area-temp;
else
area = area+10-temp;
System.out.println("Area of square is "+area+" square
centimeters");
}
}
Execution Screenshot: