新手筆記之判斷一點是否在圓內

//判斷一個點是否在以(0,0)爲圓心,半徑不定的圓內
import java.util.Scanner;


import javax.swing.JOptionPane;
public class Study4 {
public static void main(String[] args) {
int x = 0;//圓心x座標
int y = 0;//圓心y座標

Scanner input =new Scanner(System.in);
System.out.println("輸入圓的半徑r : ");
int r = input.nextInt();//圓的半徑

System.out.println("輸入該點的橫座標a : ");
int a = input.nextInt();//點的a座標

System.out.println("輸入該點的縱座標b: ");
int b = input.nextInt();//點得b座標

int c = a*a + b*b;

if(c < r*r)
System.out.println("在圓內");
else 
System.out.println("在圓外");
}}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章