20155336 "Java Programming" experiment one (familiar with Java Development environment) Experimental report

Source: Internet
Author: User

20155336 "Java Programming" experiment one (familiar with Java Development environment) Experimental report

Experimental content

    • 1. Compile and run a simple Java program using the JDK;
    • 2. Edit, compile, run, and debug Java programs using Eclipse.

Experimental knowledge points

    • JVM, JRE, JDK installation location and differences;
    • command line run JAVAC;JAVA;JAVAC-CP; JAVA-CP;
    • The setting method and application of Path,classpath,sourcepath;
    • Package management: package;import;javac-d;
    • Eclipse (Netbeans) manages Java projects, debugging: breakpoints, stepping, etc.;
    • Java basic syntax: type and type conversion; variables; operators; Process control, etc.;
    • The use of the JDK help documentation.
Experiment One

Open the Xfce terminal in the lab building and enter the cd Code command Code . Enter the mkdir 20155336 command to set up the experiment directory. Enter the cd 20155336 command into the experiment directory, enter a similar setup for the mkdir exp1 First experiment directory, enter the experiment directory cd exp1 , enter the gedit Hello.java edit Hello.java , and enter the following code:

1 package ljp;2 import java.util.Scanner;3 public class Hello{4   public static void main(String[] args){5       System.out.println("Input your first name, please:");6       Scanner s = new Scanner(System.in);7       String name = s.next();8       System.out.println("Hello " + name + " !");9    }10 }

After the code has been lost,. Enter the javac -d . Hello.java command to compile the code, enter the java ljp.Hello command to run and complete the experiment one!

Experiment two (using idea to edit, compile, run, and debug Java programs)
    • It was supposed to work in idea, and on the day of the experiment my idea went wrong, saying it was lost, so I used the eclipse in the lab building.
    • After creating new project (HELLOJDB) for Java in idea, follow the instructions and enter the following code

    • Click on the left side of the line where you want to set a breakpoint, and a red dot represents the set breakpoints.
    • On the Run menu above find Debug ... To perform one-step debugging:
    • The final success, and turn over the blue ink cloud

Experiment Three
    • Code:

      import java.util.Scanner;public class shiyan1 { public static void main(String[] args){int c;double a,b;Scanner scanner = new Scanner(System.in);while(true){ System.out.printf("输入两个数");a = scanner.nextDouble();b = scanner.nextDouble();System.out.printf("输入1234分别进行+-*/运算");c = scanner.nextInt();switch(c){case 1:System.out.printf("%d+%d=%d",a,b,a+b);break;case 2:System.out.printf("%d-%d=%d"  ,a,b,a-b);break;case 3:System.out.printf("%d*%d=%d",a,b,a*b);break;case 4:System.out.printf("%d/%d=%d",a,b,a/b);break;}}    }}
    • Operation Result:

Idea:

Problems encountered in the experiment
 在用swich语句时没有在每个case语句后面加break;导致程序通过了编译但是运行时把当前情况之后的每一个case都运行了一遍。 在做除法时,如果被除数比出书小,那么输出的结果为0;原因是把输入的数a,b都定义为了int型,将其改为double就可以解决问题。
Inspiration and experience of experiment
|步骤        | 耗时          | 百分比     |  |需求分析     | 10min        |    10%    ||设计         | 20min        |   20%     ||代码实现     | 30min         |    30%    ||测试        | 10min         |    10%     | |分析总结     |30min         |    30%      |

20155336 "Java Programming" experiment one (familiar with Java Development environment) Experimental report

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.