返回列表 發帖
104
  1. import java.util.Scanner;
  2. public class JPA104{
  3.         public static void main(String[] args){
  4.                 Scanner s=new Scanner(System.in);
  5.                 Double x1,x2,y1,y2;
  6.                 try{
  7.                         x1=s.nextDouble();
  8.                         y1=s.nextDouble();
  9.                         x2=s.nextDouble();
  10.                         y2=s.nextDouble();
  11.                 }
  12.                 catch(Exception e){
  13.                         System.out.print("error");
  14.                         s.close();
  15.                         return;
  16.                 }
  17.                 s.close();
  18.         System.out.printf("%.4f", Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2)));
  19.         }
  20. }
複製代碼
105
複製代碼
106
  1. import java.util.Scanner;
  2. public class JPA106{
  3.         public static void main(String[] args){
  4.                 Scanner s=new Scanner(System.in);
  5.                 int a[]={0,0,0,0};
  6.                 int big,small;
  7.                 for(int i=0;i<=3;i++){
  8.                         try{
  9.                                 a[i]=s.nextInt();
  10.                         }
  11.                         catch(Exception e){
  12.                                 a[i]=0;
  13.                                 s.next();
  14.                         }
  15.                 }
  16.                 s.close();
  17.                 big=a[0]>a[1]?a[0]:a[1];
  18.                 big=big>a[2]?big:a[2];
  19.                 big=big>a[3]?big:a[3];
  20.                 small=a[0]<a[1]?a[0]:a[1];
  21.                 small=small<a[2]?small:a[2];
  22.                 small=small<a[3]?small:a[3];
  23.                 System.out.println("smallest:"+small);
  24.                 System.out.println("largest:"+big);
  25.         }
  26. }
複製代碼
202
  1. import java.util.Scanner;
  2. public class JPA202{
  3.         public static void main(String[] args){
  4.                 Scanner s=new Scanner(System.in);
  5.                 int a;
  6.                 try{
  7.                         a=s.nextInt();
  8.                 }
  9.                 catch(Exception e){
  10.                         System.out.print("error");
  11.                         s.close();
  12.                         return;
  13.                 }
  14.                 s.close();
  15.                 if(a%2==0){
  16.                         System.out.print(a+" is an even number.");
  17.                 }else{
  18.                         System.out.print(a+" is an odd number.");
  19.                 }
  20.         }
  21. }
複製代碼
205
  1. import java.util.Scanner;
  2. public class JPA205{
  3.     public static void main(String[] args){
  4.         Scanner s=new Scanner(System.in);
  5.         int a,b=0;
  6.         try{
  7.             a=s.nextInt();      
  8.         }
  9.         catch(Exception e){
  10.             System.out.print("error");
  11.             s.close();
  12.             return;
  13.         }
  14.         try{
  15.             b=s.nextInt();      
  16.         }
  17.         catch(Exception e){
  18.             System.out.print("error");
  19.             s.close();
  20.             return;
  21.         }
  22.         s.close();
  23.         if(a<0||a==0){
  24.             System.out.print("error");
  25.             return;
  26.         }
  27.         if(b<0||b==0){
  28.             System.out.print("error");
  29.             return;
  30.         }
  31.         for(int i=b;i>=1;i--){
  32.             if(a%i==0 && b%i==0){
  33.                 System.out.print(i);
  34.                 return;
  35.             }
  36.         }
  37.     }
  38. }
複製代碼

TOP

返回列表