頭先上左陶陶(424)個Blog,見到佢有個C 版既畢氏定理計數機。所以我又學佢,用JAVA寫個差唔多既野啦。不過可惜啦,我又唔記得左2次方嗰個method係點打,就只好用D低B 計 ,雖然business logic係差左少少,不過好過冇啦,反正compile左都冇人知 (> ~ <) :
-----------------------------------
package pythcalc; //冇用既句子
public class Main {
public static void main(String[] args) {
int a=1; //declare a ( 1 可以改 )
int b=2; //declare b ( 2 可以改 )
double d=(a*a)+(b*b); //呢度係低能既地方,a 2次方 = a x a
double c=Math.sqrt(d); //開方
System.out.println("The c is "+c); //出answer
}
}
------------------------------------
咁都得掛,講明先,如果冇IDE,我點寫到咁perfect 喎,係咁啦~
下個blog會講下Chrome OS ! (...頂,又講電腦)
PS:”(於打blog之後15分鐘打既):
終於比我知道次方數點計啦...原來係"power”
Math.pow(a,2); // 咁就係計a既2次方,原來只係咁咋,嘥左我D心機 -.-
周兄言重,
回覆刪除大家交流下,
請周兄指教指教
package pythcalc;
import java.util.Scanner;
public class pythcalc {
public static void main(String[] args) {
Scanner ad = new Scanner(System.in);
System.out.print("a: ");
float a = ad.nextInt();
Scanner bd = new Scanner(System.in);
System.out.print("b: ");
float b = bd.nextInt();
float c =(float) (Math.pow(a,2) + Math.pow(b,2));
System.out.printf("c:%f",Math.sqrt(c) );
}}
Java好似冇c咁短咁,都係回歸c的懷抱好啲
講真,我真係對 Scanner 呢隻野唔係好熟
回覆刪除如果唔係我黠會用最簡單既方法完成佢 =.="
我連conversion都避開唔攪,你就竟然用埋
好野!
計我話,如果Program可以User-Friendly就成功啦....
回覆刪除我既建議係咁 :
package pythcalc;
import java.util.Scanner;
import static java.lang.System.out;
public class Main {
public static void main(String [] args){
Scanner amethod=new Scanner(System.in);
Scanner bmethod=new Scanner(System.in);
out.println("Please input the value of a :");
double a=amethod.nextDouble();
if (a<0) {
out.println("This is a negative number. ");
out.println("PS: You don't need to type the negative sign because it'll become positive after square.");
}
if (a>0) out.println("This is a positive number.Well done!");
out.println("Please input the value of b :");
double b=bmethod.nextDouble();
if (b<0){
out.println("This is a negative number.");
out.println("PS: You don't need to type the negative sign because it'll become positive after square.");
}
if (b>0) out.println("This is a positive number. Good Job!");
double c=Math.sqrt(Math.pow(a, 2)+Math.pow(b, 2));
out.println("The value of c should be : "+c);
}
}
嘩,原來咁就3年。
回覆刪除