0
Hovercraft. Code Coach Java
I’m very stuck. New to programming. Don’t know what I did wrong public class Program { public static void main(String[] args) { int num = 0; String prof = "Profit"; String bro = "Broke Even"; String loss = "Loss"; try{ num = Integer.parseInt(args[0]); }catch(NumberFormatException nfe){ } if (num <= 5){ System.out.println(loss); } else if (num == 7){ System.out.println(bro); } else System.out.println(prof); } }
4 Respuestas
+ 4
change
int num = 0;
to
int num = new java.util.Scanner(System.in).nextInt();
to input
+ 2
that worked perfectly. thank you. so is any part of my code obsolete after that?
+ 1
nope Yazen it's good
0
If the input is 6, what will it print?
You can write
else if(num==6){
System.out.println(loss);}