Lab 03
Lab 03
Semeste
Lab Manual
OOP
You can give any number of arguments after giving the .class file name separated by space. Space is
used as a delimiter to specify the number of command line arguments to the interpreter.
Example:
Javac showArgs.java
Java showArgs
Dr. M. Bilal Shahnawaz Lab-03 1
2nd- Lab-03: Implementing Different Concepts of Java
Semeste
Output: code will execute without any output, as no command line arguments are passed in it.
To pass the command line arguments, we will re-run the code as follows:
Argument 0=hello
Argument 1=world
By default Arguments are passed as a String array to the main method of a class.
Try to run the following code 3 times. Firstly by giving two arguments as input during run time.
Secondly by giving three arguments and for the last time by giving four number of arguments
and compare the outputs.
The following window opens. Give arguments separated by space as shown below.
Output on Console:
Argument 0 = OOP
Argument 1 = lab
Argument 2 = 3
Argument 3 = Numl
The syntax new Scanner(System.in) creates an object of the Scanner type. The syntax Scanner
input declares that input is a variable whose type is Scanner. The whole line Scanner input =
newScanner(System.in) creates a Scanner object and assigns its reference to the variable input. An
object may invoke its methods. To invoke a method on an object is to ask the object to perform a task.
Example
Pass username and password in command line arguments and display them on the console.
Task 1:
Take your name and registration number as input from user and generate the following
output. (Note: Output must be similar as shown here)
Task 2:
Take radius of circle from user and calculate area and circumference of circle.
Task 3:
Task 4:
Take three numbers from user and calculate their average. Output should be like this.
Task 5:
Write a program to convert kilometers into meters where user will input distance in kilometer
and the program will convert distance into meters.