search
HomeJavaJavaBasejava learning main function parameter passing

java learning main function parameter passing

Objective

(1). Create a class and write the program source code in the editor;

Note:

The command line parameters are array args of String type in the main method. You can use the Integer.valueOf() method to convert the string into an integer type, for example:

int number= Integer.valueOf(“12321421”)

The parameters of this method can only be numeric strings

(2), compile the program;

(3), run the program.

Online video learning tutorial sharing: java free video tutorial

Experimental part

Experimental code:

public class Average {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		//获取三个字符参数
		String one = args[0];
		String two = args[1];
		String three = args[2];
			
		//将三个字符参数转为浮点型
		double int_One = Double.valueOf(one).doubleValue();
		double int_Two = Double.valueOf(two).doubleValue();
		double int_Three = Double.valueOf(three).doubleValue();
		
		double average = (int_One + int_Two + int_Three) / 3;
		System.out.println("平均数为:"+average);				
	}
}

Program in MyEclipse, try the cmd command to compile and run.

Command line to compile java files:

javac Average.java

PS: javac is the command to compile java files, Average.java is your java file

command Run the java file:

java Average 3 4 5

PS: java is the command to run the java file, Average is the Java file name, and 3, 4, and 5 are the parameters to be passed to the main function.

Run results:

java learning main function parameter passing

Recommended related articles and tutorials: Getting started with java development

The above is the detailed content of java learning main function parameter passing. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:CSDN. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment