Pagi ini saya akan membagikan tentang bagaimana membandingkan biaya pada pemrograman java,..
Langsung saja di coba, . .
import java.util.Scanner;
public class CompareCost {
public static void main(String[] iriahus) {
@SuppressWarnings("resource")
Scanner s = new Scanner(System.in);
System.out.print("Enter weight and price for package 1: ");
double weight1 = s.nextDouble();
double price1 = s.nextDouble();
double betterPrice1 = price1 / weight1;
System.out.print("Enter weight and price for package 2: ");
double weight2 = s.nextDouble();
double price2 = s.nextDouble();
double betterPrice2 = price2 / weight2;
if (betterPrice1 < betterPrice2) {
System.out.println("Package 1 has a better price");
} else {
System.out.println("Package 2 has a better price");
}
}
}
Semoga bermanfaat, . .
0 Response to "Membandingkan Biaya"
Post a Comment