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); } }

6th Feb 2020, 1:12 AM
Yazen
Yazen - avatar
4 Respuestas
+ 4
change int num = 0; to int num = new java.util.Scanner(System.in).nextInt(); to input
6th Feb 2020, 1:52 AM
BroFar
BroFar - avatar
+ 2
that worked perfectly. thank you. so is any part of my code obsolete after that?
6th Feb 2020, 2:46 AM
Yazen
Yazen - avatar
+ 1
nope Yazen it's good
6th Feb 2020, 2:59 AM
BroFar
BroFar - avatar
0
If the input is 6, what will it print? You can write else if(num==6){ System.out.println(loss);}
15th Aug 2020, 7:00 AM
Ebney Samrat