1. 程式人生 > 實用技巧 >基於VirtualBox安裝Ubuntu圖文教程

基於VirtualBox安裝Ubuntu圖文教程

技術標籤:C語言

判斷座標點所在範圍

從鍵盤輸入一個座標點(x,y)的值,判斷該座標點是否在中心點在原點(0,0)、長為10、寬為5的矩形內。矩形所在位置如下圖所示。

判斷座標點是否在矩形內.jpg請編寫一個程式,從鍵盤輸入一個座標點的橫座標及縱座標的值,輸出判斷結果。

輸入格式:

在一行內輸入兩個數(實型數),可以用一到多個空格或回車分隔

輸出格式:

(1)如果該座標在矩形內(包括邊界),則輸出“In the rectangle” (2)如果該座標不在矩形內(邊界之外),則輸出“Not in the rectangle”

輸入樣例1:

在這裡給出一組輸入。例如:

2 2

輸出樣例1:

在這裡給出相應的輸出。例如:

In the rectangle

輸入樣例2:

在這裡給出一組輸入。例如:

6 4.0

輸出樣例2:

在這裡給出相應的輸出。例如:

Not in the rectangle

程式碼如下(嘻嘻嘻):

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// TODO 自動生成的方法存根

		Scanner in =new Scanner(System.in);

		float x=in.nextFloat( );

		float y=in.nextFloat( );

		if(x<=5&&x>=-5)

		{

			if(y<=2.5&&y>=-2.5)

			{

			System.out.print("In the rectangle");

			}

		}

		else

		{

			System.out.print("Not in the rectangle");

		}

	}

}