Delimiters Uses:
The Scanner class basically parses input from the source into tokens by using delimiters to identify the token boundaries.
The default delimiter is whitespace:[ \t\n\x0B\f\r]
package com.java;
import java.util.Scanner;
public class Delimeter
{
public static void main(String args[])
{
String input = "1 Hi 2 Hi Danish Hi Gahlout Hi";
Scanner s = new Scanner(input).useDelimiter("\\s*Hi\\s*");
System.out.println(s.nextInt());
System.out.println(s.nextInt());
System.out.println(s.next());
System.out.println(s.next());
s.close();
}
}
Output:
1
2
Danish
Gahlout
2
Danish
Gahlout
Command Line Arguments
Java application can accept any number of arguments directly from the command line. The user can enter command-line arguments when invoking the application. When running the java program from java command, the arguments are provided after the name of the class separated by space.
public class RectangleUser
{
public static void main(String args[])
{
int width;
int height;
int area;
int perimeter;
width=Integer.parseInt(args[0]);
height=Integer.parseInt(args[1]);
area=width*height;
perimeter=2*(width+height);
System.out.println("Area of Rectangle: "+area);
System.out.println("Perimeter of Rectangle: "+perimeter);
}
}


