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 Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)