+ 1

Can someone please help me with this code for the code coach Argentina?

It always outputs Pesos. This is my code: public class Program { public static void main(String[] args) { double Pesos=1; double Dollars=0.02; double p=(Dollars*0.02); double d=(Pesos/0.02); if(p<d) { System.out.println("Pesos"); }if (p>d) { System.out.println("Dollars"); } } }

3rd Mar 2021, 4:05 AM
Ava
Ava - avatar
4 Antworten
+ 2
Thank you Rostislsv!
3rd Mar 2021, 4:31 AM
Ava
Ava - avatar
+ 1
Btw I also tried using an else statement. Idk if I used it correctly though.
3rd Mar 2021, 4:06 AM
Ava
Ava - avatar
+ 1
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); int pesos = input.nextInt(); int dolars = input.nextInt(); if(pesos/80<dolars){ System.out.println("Pesos"); }else{ System.out.println("Dollars"); } } }
3rd Mar 2021, 4:16 AM
SammE
SammE - avatar
+ 1
dont convert both values either convert dollar to pesos and compare it to pesos or convert pesos to dollar and compare it to dollar eg: public class Program { public static void main(String[] args) { double Pesos=1; double Dollars=0.02; double p=(Dollars*0.02); if(p<Dollars) { System.out.println("Pesos"); }if (p>Dollars) { System.out.println("Dollars"); } } }
3rd Mar 2021, 12:26 PM
Nothing
Nothing - avatar