package one;
import java.util.Scanner;
public class one_o {
public static void main(String[] args) {
/**
*
* 1.1算數表達式
*/
/*System.out.printf("%d\n",1+2);
System.out.printf("%d\n",3-4);
System.out.printf("%d\n",5*6);
System.out.printf("%d\n",8/4);
System.out.printf("%d\n",8/5);
System.out.printf("%.1f\n",8.0/5.0);
System.out.printf("%.2f\n",8.0/5.0);
//System.out.printf("%.1f\n",8/5);
//System.out.printf("%d\n",8.0/5.0);
System.out.printf("%.8f", 1+2*Math.sqrt(3)/(5-0.1));
*/
/**
* 1.2變量及其輸入
*
*/
/*Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
System.out.println(a+b);*/
//圓柱體表面積
/*Scanner sc1=new Scanner(System.in);
double r,h,s,s1,s2;
r=sc1.nextDouble();
h=sc1.nextDouble();
s1=Math.PI*r*r;
s2=2*Math.PI*h;
s=2*s1+s2;
System.out.printf("Area= %.3f",s);*/
/**
* 1.3順序結構程序設計
*/
//三位數反轉(1)
/*Scanner sc2=new Scanner(System.in);
int n=sc2.nextInt();
System.out.printf("%d%d%d",n%10,n/10%10,n/100);*/
//三位數反轉(2)當最高位爲0時
/*Scanner sc3=new Scanner(System.in);
int n=sc3.nextInt();
int m=(n%10)*100+(n/10%10)*10+(n/100);
System.out.printf("%03d",m);*/
//交換變量(1)三變量法
/*Scanner sc4=new Scanner(System.in);
int a=sc4.nextInt();
int b=sc4.nextInt();
int t;
t=a;
a=b;
b=t;
System.out.printf("%d %d",a,b);*/
//變量交換(2)不建議
/*Scanner sc5=new Scanner(System.in);
int a=sc5.nextInt();
int b=sc5.nextInt();
a=a+b;
b=a-b;
a=a-b;
System.out.printf("%d %d",a,b);*/
//變量交換(3)最適合
Scanner sc6=new Scanner(System.in);
int a=sc6.nextInt();
int b=sc6.nextInt();
System.out.printf("%d %d",b,a);
}
}
/**
* 1.4分支結構程序設計
*/
//雞兔同籠
/*int a,b,n,m;//雞、兔、總數、腿數
Scanner sc7=new Scanner(System.in);
n=sc7.nextInt();
m=sc7.nextInt();
a=(4*n-m)/2;
b=n-a;
if(m%2==1||a<0||b<0) {
System.out.println("no answer");
}
else {
System.out.printf("%d %d", a,b);
}*/
//三整數排序(2)
/*int a,b,c;
Scanner sc8=new Scanner(System.in);
a=sc8.nextInt();
b=sc8.nextInt();
c=sc8.nextInt();
if(a<=b && b<=c) System.out.printf("%d %d %d", a,b,c);
else if(a<=c && c<=b) System.out.printf("%d %d %d", a,c,b);
else if(b<=a && a<=c) System.out.printf("%d %d %d", b,a,c);
else if(b<=c && c<=a) System.out.printf("%d %d %d", b,c,a);
else if(c<=a && a<=b) System.out.printf("%d %d %d", c,a,b);
else if(c<=b && b<=a) System.out.printf("%d %d %d", c,b,a);*/
//三整數排序(3)
/*int a,b,c,t;
Scanner sc9=new Scanner(System.in);
a=sc9.nextInt();
b=sc9.nextInt();
c=sc9.nextInt();
if(a>b) {
t=a;
a=b;
b=t;
}
if(a>c) {
t=a;
a=c;
c=t;
}
if(b>c) {
t=b;
b=c;
c=t;
}
System.out.printf("%d %d %d", a,b,c);*/
//三整數排序(4) 推薦
int a,b,c,x,y,z;
Scanner sc10=new Scanner(System.in);
a=sc10.nextInt();
b=sc10.nextInt();
c=sc10.nextInt();
x=a;if(b<x) x=b;if(c<x) x=c;
z=a;if(b>z) z=b;if(c>z) z=c;
y=a+b+c-x-z;
System.out.printf("%d %d %d",x,y,z);
算法競賽入門學習
一邊看書一邊將原文中的C語言改爲Java語言編寫