"Java" Tij demo Java Main method gets parameters from the command line __java

Source: Internet
Author: User
Tags java se


As we all know, Java programs can receive parameters from the command line, and the following program demonstrates how to get command-line arguments:

The code is as follows:


* * Demo Main method receive string from console
*thinking in Java Test 2.10
* @author: Wolfofsiberian/Public
class Tij_ test2_10{public
	static void Main (String args[]) {
		//Determine whether the console passes in the parameter
		if (0!= args.length) {for
			(int i=0;i <args.length;i++) {
				System.out.println ("args[" +i+ "]="));
			}
		else{
			System.out.println ("Command line is empty!");}}	


Execution Results:

(See from the execution result, when the command line passes in the parameter, use the space match to divide each parameter, and then save each parameter into a string array)


E:\Java se\thinking in Java>java tij_test2_10
Command line is empty!

E:\Java se\thinking in Java>java tij_test2_10 A B C D E
args[0]=a
args[1]=b
Args[2]=c
ARGS[3]=D
args[4]=e

E:\Java se\thinking in Java>java tij_test2_10 A B C D E aadfa afjad;fja;
Args[0]=a
args[1]= B
Args[2]=c
Args[3]=d
args[4]=e
Args[5]=aadfa
Args[6]=afjad;fja;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.