Java compile and run practical demonstration in the console

First, you need to know some common commands of CMD under windows
1. Enter a certain disk (disk name + :)

//进入d盘
D:
//进入E盘
E:

2. Enter the folder (cd + "space" + "folder name")
Note: "\" backslashes must be used in the command line, not "/" slashes.
For example, if I want to enter my E disk\java\test, I need to enter it as shown in the figure.

cd java\test

Insert picture description here
Like the picture is success

Now that you know these two, you can compile Java~


Practice below

Q1: The result of 1055-(383+545) is output on the console, and the result is as follows:

127


Here only let the output result 127, so we will make the code simpler.

1. Create a new txt file in the folder (it is recommended to create a test folder specifically, the path should not be too complicated, it is convenient to organize and summarize, here pay attention to the folder name not to set Chinese, otherwise it is very troublesome!), open the txt text and enter the following Code.

public class test01{
    
    
	public static void main(String[]args){
    
    
		System.out.println("127");
		}
}

Save and exit, and then change the file name to test01, which is the class in the code. The file name must be consistent with the class name. The suffix was changed from .txt to .java.

As shown in the figure, the file name is consistent with the class name, and the suffix is ​​.java.
Insert picture description here
2. Win+R enter cmd to open the command console.

Enter the folder where test01.java was just stored, and you
won’t see the top cmd commands
Insert picture description here
3. Compile Java files

javac test01.java

After success, a test01.class file will be generated in the current directory

4. Run the file

Java test

Below is the actual operation diagram
Insert picture description here
Q2: Write the program and display the result of the following formula:
Insert picture description here
here is the problem-solving code posted, and the other steps are exactly the same as Q1.
(Pay attention to the file name to be consistent with the class name~)

public class test02{
    
        
public static void main(String[] args){
    
            
double x;       
 x=(9.5*4.5-2.5*3)/(45.5-3.5);        
 System.out.println(x);    
}}

The above is the entire content of this article~ Thank you for reading~
(If there are errors, please raise them and I will correct them in time~)

Guess you like

Origin blog.csdn.net/ybytlidazui/article/details/108632986