返回列表 發帖
本帖最後由 高鋐鈞 於 2023-11-4 12:06 編輯

104
  1. import java.util.*;
  2. public class Ch05 {
  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.                         System.out.printf("%.4f",Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
  12.                 }catch(Exception e){
  13.                         System.out.println("error");
  14.                         s.close();
  15.                 }
  16.         }
  17. }
複製代碼
105
  1. import java.util.*;
  2. public class Ch01 {
  3.         public static void main(String args[]) {
  4.                 Scanner s=new Scanner(System.in);
  5.                 String dreams = "There are moments in life when you miss someone so much that "
  6.                 + "you just want to pick them from your dreams and hug them for real! Dream what "
  7.                 + "you want to dream;go where you want to go;be what you want to be,because you have "
  8.                 + "only one life and one chance to do all the things you want to do";
  9.                 String search=s.nextLine();
  10.                 int first,last;
  11.                 String capture;
  12.                 first=dreams.indexOf(search);
  13.                 last=dreams.lastIndexOf(search);
  14.                 if(first==-1){
  15.                         first=0;
  16.                         last=0;
  17.                         capture="";
  18.                 }else if(first==last){
  19.                         last=0;
  20.                         capture=dreams.substring(first);
  21.                         first++;
  22.                 }else {
  23.                         capture=dreams.substring(first, last+search.length());
  24.                         first++;
  25.                         last++;
  26.                 }
  27.                 System.out.println("first:"+first);
  28.                 System.out.println("last:"+last);
  29.                 System.out.println("capture:"+capture);


  30.         }
  31. }
複製代碼
106
  1. import java.util.*;
  2. public class Ch02 {
  3.         public static void main(String args[]) {
  4.                 Scanner s=new Scanner(System.in);
  5.                 int a,b,c,d;
  6.                 try{
  7.                         a=s.nextInt();
  8.                         if(a<0)
  9.                                 a=0;
  10.                 }catch(Exception e){
  11.                         a=0;
  12.                         s.next();
  13.                 }try{
  14.                         b=s.nextInt();
  15.                         if(b<0)
  16.                                 b=0;
  17.                 }catch(Exception e){
  18.                         b=0;
  19.                         s.next();
  20.                 }try{
  21.                         c=s.nextInt();
  22.                         if(c<0)
  23.                                 c=0;
  24.                 }catch(Exception e){
  25.                         c=0;
  26.                         s.next();
  27.                 }try{
  28.                         d=s.nextInt();
  29.                         if(d<0)
  30.                                 d=0;
  31.                 }catch(Exception e){
  32.                         d=0;
  33.                 }
  34.                 int tep1,tep2;
  35.                 tep1=Math.min(a, b);
  36.                 tep1=Math.min(tep1, c);
  37.                 tep1=Math.min(tep1, d);
  38.                 tep2=Math.max(a, b);
  39.                 tep2=Math.max(tep2, c);
  40.                 tep2=Math.max(tep2, d);
  41.                 System.out.println("smallest:"+tep1);
  42.                 System.out.println("largest:"+tep2);
  43.                
  44.         }
  45. }
複製代碼
202
  1. import java.util.*;
  2. public class Ch03 {
  3.         public static void main(String args[]) {
  4.                 Scanner s=new Scanner(System.in);
  5.                 int a;
  6.                 try{
  7.                         a=s.nextInt();
  8.                 }catch(Exception e){
  9.                         System.out.println("error");
  10.                         return;
  11.                 }
  12.                 if(a%2==0){
  13.                         System.out.println(a+" is an even number.");
  14.                 }else{
  15.                         System.out.println(a+" is an odd number.");
  16.                 }
  17.         }
  18. }
複製代碼
205
  1. import java.util.Scanner;
  2. public class Ch04 {
  3.         public static void main(String args[]) {
  4.                 Scanner s=new Scanner(System.in);
  5.                 int a,b;
  6.                 try{
  7.                         a=s.nextInt();
  8.                         b=s.nextInt();
  9.                         if(a<0||a>100||b<0||b>100){
  10.                                 System.out.println("error");
  11.                                 return;
  12.                         }
  13.                 }catch(Exception e){
  14.                         System.out.println("error");
  15.                         return;
  16.                 }
  17.                 int x=0;
  18.                 for(int i=1;i<=Math.max(a, b);i++){
  19.                         if(a%i==0&&b%i==0){
  20.                                 x=i;
  21.                         }
  22.                 }
  23.                 System.out.print(x);
  24.         }
  25. }
複製代碼

TOP

返回列表