Skip to content
Advertisement

How do I make the returned integer value in this program print a message, depending on the value?

I have semi-successfully coded this program. As it stands, it prints an integer value as a result of what you type in. The only results can be 0, 1, or 2. I am wondering how to make java display a message for each one of those 3 integer values. For instance, a returned result of 0 might make it print “You received no ticket”, while a result of 2 would say “You’re going to jail, buddy!” Any tips on how I could do this?

I know the answer is probably very simple; bear with me, as I am just starting out 🙂

Thanks!

JavaScript

Advertisement

Answer

You can just go with simple if-else on returned value. I am giving you an example with some minor logical improvements.

JavaScript

this line will only reach is the speed is already greater than 65. So you can do this:

JavaScript

Similar for this:

JavaScript

Make it like this:

JavaScript

And finally the full code:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement