It's UWAweek 16 (1st semester, week 7)

help2005

This forum is provided to promote discussion amongst students enrolled in CITS2005 Object Oriented Programming.

Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.

How do I ask a good question?
Displaying selected article
Showing 1 of 53 articles.
Currently no other people reading this forum.


 UWA week 11 (1st semester, week 3) ↓
SVG not supported

Login to reply

👍?
helpful
11:07am Mon 11th Mar, Andrew G.

There are a couple of options for how to get input in a Java program that we have covered so far...

You can indeed use Scanner. You can construct a Scanner object wherever it makes sense (probably in main, for a little example like this) and use it to read input from stdin. Our slides and the documentation for Scanner have various examples on how to use Scanner and the methods it provides.

Alternatively, you could parse your input from command line arguments. Recall that the String[] args parameter of the main method is a list of the arguments passed when your program was run from the command line. You can use something like Integer.parseInt() to parse one of the arguments as an input that you can then pass to your method.

Of course there are several other ways of getting input into your programs at runtime, but either of these should be suitable for your purposes.

Cheers,
Gozz

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  5:07AM Sep 06 2023
Privacy policy