Change Position: The room that Patrick and Johnny were staying was very big. They felt lazy to walk inside the room from the bed’s location to another location. So they wanted to change the position of the bed. The shape of the room is a Square. They decided to place the bed at the centre of the room so that their walking distance would be minimised. Can you please help them in placing the bed at the centre?
Given the coordinates of the left bottom vertex of the square room and the length of the side, you need to write a program to determine the coordinates of the centre of the room.
[Assumption — Length of the side is always even]
Input Format:
Input consists of 3 integers. The first integer corresponds to the x-coordinate of the left bottom vertex. The second integer corresponds to the y-coordinate of the left bottom vertex. The third integer corresponds to the length of the square.
Output Format:
Refer Sample Input and Output for exact formatting specifications.
Sample Input:
Enter the x-coordinate of the left bottom vertex
10 30 16
Sample Output:
18 38
Solution
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y = sc.nextInt();
int l = sc.nextInt();
System.out.println((x + l / 2) + " " + (y + l / 2));
}
}
Happy Learning – If you require any further information, feel free to contact me.