Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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..!! */

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote