Kali ini saya akan membagikan tentang penukaran valuta asing pada pemrograman java, . .
silahkan dicoba, . .
import java.util.Scanner;
public class CurrencyExchange {
public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner s = new Scanner(System.in);
System.out.print("Enter the exchange rate from dollars to Rp: ");
double rate = s.nextDouble();
System.out.print("To convert, enter 0 ($ to Rp) and 1 (vice versa): ");
int pick = s.nextInt();
if (pick == 0) {
System.out.print("Enter the $ amount: ");
double $ = s.nextDouble();
double result = $ * rate;
System.out.println("$" + $ + " is Rp" + result);
}
else if (pick == 1){
System.out.print("Enter the Rp amount: ");
double Rp = s.nextDouble();
double result = Rp / rate;
System.out.println("Rp" + Rp + " is $" + result);
} else {
System.out.println("Invalid input");
}
}
}
Semoga bermanfaat, . .
0 Response to "Penukaran Valuta Asing"
Post a Comment