返回列表 發帖
  1. [code]import java.util.*;
  2. public class Ch01 {

  3.         public static void main(String[] args) {
  4.                 // TODO 自動產生的方法 Stub
  5.                 Scanner s=new Scanner(System.in);
  6.         double x1=0,x2=0,y1=0,y2=0;
  7.         double df;
  8.         try
  9.         {
  10.                 x1=s.nextDouble();
  11.                 y1=s.nextDouble();
  12.                 x2=s.nextDouble();
  13.                 y2=s.nextDouble();
  14.         }catch(Exception e){
  15.                 System.out.println("error");
  16.                 return;
  17.         }
  18.         df=Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2));
  19.         System.out.printf("%.4f",df);
  20.         
  21.         }

  22. }
複製代碼
  1. import java.util.*;
  2. public class Ch02 {

  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 sea="",res="";
  10.                 int fir=0,la=0;
  11.                         sea=s.nextLine();
  12.         fir=dreams.indexOf(sea);
  13.         la=dreams.lastIndexOf(sea);
  14.         if(fir==-1){
  15.                 fir=0;
  16.                 la=0;
  17.         }
  18.         else
  19.         {
  20.                 if(fir==la)
  21.                 {
  22.                         res=dreams.substring(fir);
  23.                         la=0;
  24.                         fir+=1;
  25.                 }
  26.                 else
  27.                 {
  28.                         res=dreams.substring(fir,la+sea.length());
  29.                         la+=1;
  30.                         fir+=1;
  31.                 }
  32.         }
  33.         System.out.println("first:"+fir);
  34.         System.out.println("last:"+la);
  35.         System.out.println("capture:"+res);
  36.         }

  37. }
複製代碼
  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=0,b=0,c=0,d=0,ef=0,f=0;
  6.         try
  7.         {
  8.                 a=s.nextInt();
  9.                 if(a<0)
  10.                         a=0;
  11.         }
  12.         catch(Exception e)
  13.         {
  14.                 a=0;
  15.                 s.next();
  16.         }
  17.         try
  18.         {
  19.                 b=s.nextInt();
  20.                 if(b<0)
  21.                         b=0;
  22.         }
  23.         catch(Exception e)
  24.         {
  25.                 b=0;
  26.                 s.next();
  27.         }
  28.         try
  29.         {
  30.                 c=s.nextInt();
  31.                 if(c<0)
  32.                         c=0;
  33.         }
  34.         catch(Exception e)
  35.         {
  36.                 c=0;
  37.                 s.next();
  38.         }
  39.         try
  40.         {
  41.                 d=s.nextInt();
  42.                 if(d<0)
  43.                         d=0;
  44.         }
  45.         catch(Exception e)
  46.         {
  47.                 d=0;
  48.                 s.next();
  49.         }
  50.         if(a>b)
  51.                 ef=a;
  52.         else
  53.                 ef=b;
  54.         if(c>ef)
  55.                 ef=c;
  56.         if(d>ef)
  57.                 ef=d;
  58.         if(a>b)
  59.                 f=b;
  60.         else
  61.                 f=a;
  62.         if(f>c)
  63.                 f=c;
  64.         if(f>d)
  65.                 f=b;
  66.         System.out.println("smallest:"+f);
  67.         System.out.println("largest:"+ef);
  68.         }

  69. }
複製代碼
  1. import java.util.*;
  2. public class Ch04 {

  3.         public static void main(String[] args) {
  4.                 Scanner s=new Scanner(System.in);
  5.                 int a=0,b=0,c=0;
  6.                 try
  7.                 {
  8.                         a=s.nextInt();
  9.                 }catch(Exception e)
  10.                 {
  11.                         System.out.println("error");
  12.                         return;
  13.                 }
  14.                 try
  15.                 {
  16.                         b=s.nextInt();
  17.                 }catch(Exception e)
  18.                 {
  19.                         System.out.println("error");
  20.                         return;
  21.                 }
  22.                 if(a>b)
  23.                         c=b;
  24.                 else
  25.                         c=a;
  26.                 for(int i=0;i<c;i++)
  27.                 {
  28.                         if(a%i && b)
  29.                 }

  30.         }

  31. }
複製代碼
  1. import java.util.*;
  2. public class Ch5 {

  3.         public static void main(String[] args) {
  4.                 // TODO 自動產生的方法 Stub
  5.                 Scanner s=new Scanner(System.in);
  6.                 int a=0;
  7.                 try
  8.                 {
  9.                         a=s.nextInt();
  10.                 }catch(Exception e)
  11.                 {
  12.                         System.out.println("error");
  13.                         return;
  14.                 }
  15.                 if(a%2==0)
  16.                         System.out.println(a+" is an even number.");
  17.                 else
  18.                         System.out.println(a+" is an odd number.");
  19.        
  20.         }

  21. }
複製代碼

TOP

返回列表