Ok..Jom kita sambung cara nak kira BMI pulak :
Langkah-langkahnya seperti di bawah...langkah 1 dan 2 sama je macam sebelum ni.
Andai kata sape yg x buka sebelum ni punya x pe saya ulang balik..
1. Buka repl dulu..ataupun boleh tekan link ni..( https://repl.it/ )
2. Lepas korang dah log in..dia akan tulis seperti gambar di bawah :
Lepas tu, tekan dekat button student... and dia akan keluar macam gambar bawah ni:
Lepas tu tekan project40%...and dia akan keluar macam gambar bawah ni..
P/s: Farah aku guna kau punya tau..TQ |
3. Dah buka repl dah ?.... Nanti keluar kod macam dekat bawah ni kan...
import java.util.Scanner;import java.lang.Math;
class Main{public static void main(String[] args){Scanner in = new Scanner(System.in);double a = 0;double b = 0;double c = 0;System.out.println("Press 1 for A side");System.out.println("Press 2 for B side");System.out.println("Press 3 for C side");int z = in.nextInt();if (z == 1){System.out.println("Input B");b = in.nextDouble();System.out.print("Input C");c = in.nextDouble();a = Math.sqrt(Math.pow(c,2) - Math.pow(b,2));System.out.print(" A = ");System.out.println(a);}if (z == 2){System.out.println("Input A");a = in.nextDouble();System.out.print("Input C");c = in.nextDouble();b = Math.sqrt(Math.pow(c,2) - Math.pow(a,2));System.out.print(" B = ");System.out.println(b);}if (z == 3){System.out.println("Input A");a = in.nextDouble();System.out.print("Input B");b = in.nextDouble();c = Math.sqrt(Math.pow(c,2) - Math.pow(b,2));System.out.print(" C = ");System.out.println(c);}{System.out.println("K,Bye.. Malas nak layan kau..");}}}
4. Next, korang kena delete perkataan yang ada dalam kotak ni tau :
int z = in.nextInt();5. Kalau dah delete nanti hasil dia akan jadi macam ni :
if (z == 1){
}
if (z == 2){
System.out.println("Input A");
a = in.nextDouble();
System.out.print("Input C");
c = in.nextDouble();
b = Math.sqrt(Math.pow(c,2) - Math.pow(a,2));
System.out.print(" B = ");
System.out.println(b);
}
if (z == 3){
System.out.println("Input A");
a = in.nextDouble();
System.out.print("Input B");
b = in.nextDouble();
c = Math.sqrt(Math.pow(c,2) - Math.pow(b,2));
System.out.print(" C = ");
System.out.println(c);
}
import java.util.Scanner;
import java.lang.Math;
class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
double a = 0;
double b = 0;
double c = 0;
System.out.println("Press 1 for A side");
System.out.println("Press 2 for B side");
System.out.println("Press 3 for C side");
System.out.println("Input B");
b = in.nextDouble();
System.out.print("Input C");
c = in.nextDouble();
a = Math.sqrt(Math.pow(c,2) - Math.pow(b,2));
System.out.print(" A = ");
System.out.println(a);
{
System.out.println("K,Bye.. Malas nak layan kau..");
}
}
}
6. Kemudian tukarkan ayat warna merah dalam bracket tu dengan ayat sendiri..contoh :
System.out.println("Press 1 for A side");
System.out.println("Press 2 for B side");
System.out.println("Press 3 for C side");
(p/s: klu dkt ^ ni maksudnya dia ad 3 ayat)
TUKAR JADI
System.out.println("Ada masalah nak kira BMI");
System.out.println("Jom, saya tolong kirakan..");
(p/s:kalau ^ ni 2 ayat je)
*kalau korang nak 1 atau 2 ayat, so just delete je..
7. Lepas tu tukar yang ni pulak..
8. So, nanti hasil dia akan jadi macam ni :
System.out.println("Input B");
b = in.nextDouble();
System.out.print("Input C");
c = in.nextDouble();
a = Math.sqrt(Math.pow(c,2) - Math.pow(b,2));
System.out.print(" A = ");
Jadi macam ni..ni contoh je tau :
System.out.println("Berat");
b = in.nextDouble();
System.out.print("Tinggi(dlm meter)");
c = in.nextDouble();
a = b/(Math.pow(c,2))
System.out.print(" BMI = ");
8. So, nanti hasil dia akan jadi macam ni :
import java.util.Scanner;
import java.lang.Math;
class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
double a = 0;
double b = 0;
double c = 0;
System.out.println("HYE...Guys!!!");
System.out.println(" Nak tahu BMI sendiri tak?");
System.out.println("*********************************************************");
System.out.println("Berat");
b = in.nextDouble();
System.out.print("Tinggi(dlm meter)?");
c = in.nextDouble();
a = b/(Math.pow(c,2));
System.out.println ("jangan lupa bundarkan yer..");
System.out.print("BMI = ");
System.out.println(a);
{
System.out.println("OK BYE..!!THANK YOU..JOM EXERCISE!!!");
}
}
}
(p/s: jangan tiru bulat2..boleh tukar ayat yg warna merah tu dengan ayat korang sendiri)
(yang simbol * tu saje je nak buat pembahagian kalau x nk buat pon tak pe)
9. Okay.. Sekarang dah boleh tekan RUN..
kalau nak tengok atau try boleh tekan link ni:
kalau nak tengok atau try boleh tekan link ni:
SELAMAT MAJU JAYA.. TAK FAHAM SILA COMMENT YE..
Comments
Post a Comment