عندي واجب في البرمجه وطالب مني برنامج يحول من باوند الى كيلوجرام كيف طريقة حله؟
|
كود PHP:
import java.util.Scanner;
public class JavaApplication11 {
public static void main(String[] args) {
// 1 kilogram = 2.20462262 pounds
// 1 pound = 0.45359237 kilograms
final double lbs_1 = 2.20462262;
final double kg_1 = 0.45359237;
int chos;
double result,kg,lbs;
Scanner enter = new Scanner (System.in);
System.out.print("\nEnter 1 to convert from Kg to Lbs \" OR \" 2 to convert from Lbs to Kg\" OR\" 0 to Exit : ");
chos = enter.nextInt();
while (true){
if (chos ==1)
{
System.out.print(" KG : ");
kg = enter.nextInt();
result = kg * lbs_1;
System.out.print(kg +" KG = "+ result +" Lbs ");
System.out.print("\nEnter 1 to convert from Kg to Lbs \" OR \" 2 to convert from Lbs to Kg\" OR\" 0 to Exit : ");
chos = enter.nextInt();
}
else if (chos ==2)
{
System.out.print(" Lbs : ");
lbs = enter.nextInt();
result = lbs * kg_1;
System.out.print(lbs +" Lbs = "+ result +" KG ");
System.out.print("\nEnter 1 to convert from Kg to Lbs \" OR \" 2 to convert from Lbs to Kg\" OR\" 0 to Exit : ");
chos = enter.nextInt();
}
else if (chos == 0 )
System.exit(0);
else
{
System.err.print("ERROR Enter 1 to convert from Kg to Lbs \" OR \" 2 to convert from Lbs to Kg\" OR\" 0 to Exit : ");
chos = enter.nextInt();
}
}
}
}