You are given the width and height of a picture. Print out whether it is in land
ID: 3574941 • Letter: Y
Question
You are given the width and height of a picture. Print out whether it is in landscape orientation (wider than tall), in portrait orientation (taller than wide), or square.
Complete the following file:
import java.util.Scanner;
public class PictureOrientation
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Width: ");
int width = in.nextInt();
System.out.print("Height: ");
int height = in.nextInt();
// Use an if/else if/else statement to print
// Portrait, Landscape, or Square
. . .
}
}
Explanation / Answer
import java.util.Scanner;
public class PictureOrientation{
public static void main(String []args){
Scanner in = new Scanner(System.in);
System.out.print("Width: ");
int width = in.nextInt();
System.out.print("Height: ");
int height = in.nextInt();
if(width > height ) /* wider than taller */
System.out.println("Landscape");
else if(width < height ) /* taller than wider */
System.out.println("Portrait");
else /* width is equal to height */
System.out.println("Square");
// Use an if/else if/else statement to print
// Portrait, Landscape, or Square
}
}
/*****OUTPUT**********
sh-4.3$ java -Xmx128M -Xms16M PictureOrientation
Width: 10
Height: 9
Landscape
sh-4.3$ java -Xmx128M -Xms16M PictureOrientation
Width: 10
Height: 12
Portrait
sh-4.3$ java -Xmx128M -Xms16M PictureOrientation
Width: 10
Height: 10
Square
*********OUTPUT**********/
/* Note:This code has been tested and working fine,Please do ask in case of any doubt,Thanks..!! */
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.