- [code]import java.util.*;
- public class Ch01 {
- public static void main(String[] args) {
- // TODO 自動產生的方法 Stub
- Scanner s=new Scanner(System.in);
- double x1=0,x2=0,y1=0,y2=0;
- double df;
- try
- {
- x1=s.nextDouble();
- y1=s.nextDouble();
- x2=s.nextDouble();
- y2=s.nextDouble();
- }catch(Exception e){
- System.out.println("error");
- return;
- }
- df=Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2));
- System.out.printf("%.4f",df);
-
- }
- }
複製代碼- import java.util.*;
- public class Ch02 {
- public static void main(String[] args) {
- Scanner s=new Scanner(System.in);
- String dreams = "There are moments in life when you miss someone so much that "
- + "you just want to pick them from your dreams and hug them for real! Dream what "
- + "you want to dream;go where you want to go;be what you want to be,because you have "
- + "only one life and one chance to do all the things you want to do";
- String sea="",res="";
- int fir=0,la=0;
- sea=s.nextLine();
- fir=dreams.indexOf(sea);
- la=dreams.lastIndexOf(sea);
- if(fir==-1){
- fir=0;
- la=0;
- }
- else
- {
- if(fir==la)
- {
- res=dreams.substring(fir);
- la=0;
- fir+=1;
- }
- else
- {
- res=dreams.substring(fir,la+sea.length());
- la+=1;
- fir+=1;
- }
- }
- System.out.println("first:"+fir);
- System.out.println("last:"+la);
- System.out.println("capture:"+res);
- }
- }
複製代碼- import java.util.*;
- public class Ch03 {
- public static void main(String[] args) {
- Scanner s=new Scanner(System.in);
- int a=0,b=0,c=0,d=0,ef=0,f=0;
- try
- {
- a=s.nextInt();
- if(a<0)
- a=0;
- }
- catch(Exception e)
- {
- a=0;
- s.next();
- }
- try
- {
- b=s.nextInt();
- if(b<0)
- b=0;
- }
- catch(Exception e)
- {
- b=0;
- s.next();
- }
- try
- {
- c=s.nextInt();
- if(c<0)
- c=0;
- }
- catch(Exception e)
- {
- c=0;
- s.next();
- }
- try
- {
- d=s.nextInt();
- if(d<0)
- d=0;
- }
- catch(Exception e)
- {
- d=0;
- s.next();
- }
- if(a>b)
- ef=a;
- else
- ef=b;
- if(c>ef)
- ef=c;
- if(d>ef)
- ef=d;
- if(a>b)
- f=b;
- else
- f=a;
- if(f>c)
- f=c;
- if(f>d)
- f=b;
- System.out.println("smallest:"+f);
- System.out.println("largest:"+ef);
- }
- }
複製代碼- import java.util.*;
- public class Ch04 {
- public static void main(String[] args) {
- Scanner s=new Scanner(System.in);
- int a=0,b=0,c=0;
- try
- {
- a=s.nextInt();
- }catch(Exception e)
- {
- System.out.println("error");
- return;
- }
- try
- {
- b=s.nextInt();
- }catch(Exception e)
- {
- System.out.println("error");
- return;
- }
- if(a>b)
- c=b;
- else
- c=a;
- for(int i=0;i<c;i++)
- {
- if(a%i && b)
- }
- }
- }
複製代碼- import java.util.*;
- public class Ch5 {
- public static void main(String[] args) {
- // TODO 自動產生的方法 Stub
- Scanner s=new Scanner(System.in);
- int a=0;
- try
- {
- a=s.nextInt();
- }catch(Exception e)
- {
- System.out.println("error");
- return;
- }
- if(a%2==0)
- System.out.println(a+" is an even number.");
- else
- System.out.println(a+" is an odd number.");
-
- }
- }
複製代碼 |