In: Computer Science
JAVA
Write code which takes three decimal inputs from the user, creates a circle with a radius equal to the first input and a rectangle with length and width equal to the second and third input respectively, then prints both of these shapes.
Sample run:
Type a radius: 3.7 Type a length: 4.9 Type a width: 8.6 circle with radius 3.7 rectangle with length 4.9, width 8.6
import java.util.*;
public class Sample{
public static void main(String args[]){
double radius,length,width;
Scanner input=new Scanner(System.in);
System.out.println("Type a radius:");
radius=input.nextDouble();
System.out.println("Type a length:");
length=input.nextDouble();
System.out.println("Type a width:");
width=input.nextDouble();
System.out.println("circle with radius "+radius);
System.out.println("rectangle with length "+length+", width "+width);
}
}
import java.util.*;
public class Sample{
public static void main(String args[]){
double radius,length,width;
Scanner input=new Scanner(System.in);
System.out.println("Type a radius:");
radius=input.nextDouble();
System.out.println("Type a length:");
length=input.nextDouble();
System.out.println("Type a width:");
width=input.nextDouble();
String Circle="circle with radius "+radius;
String Rectangle="rectangle with length "+length+", width "+width;
System.out.println(Circle);
System.out.println(Rectangle);
}
}