Java Experiment One report

Source: Internet
Author: User

Beijing Institute of Electronic Technology (besti)

Lab Report

Course: Java class: 1352 Name: Huang No.: 20135227

Score: Instructor: Lou Jia Peng Experimental Date: 2015.4.17

Experiment level: Preview degree: Experiment time: 15:30~18:00

Instrument Group: 27 Compulsory / elective: Elective experiment serial number:

Lab Name: familiarity with the Java development environment

Experimental purposes and requirements:

1. compiling and running a simple Java program using the JDK

2. use eclipse java procedure                                                          

3. Implement arithmetic

Experimental instrument:

Name

Model

Number

Computer

1

Laboratory Building

1

Statistics for PSP (Personal software Process) time

Steps

Time -consuming (min)

Percentage

Demand analysis

10

10%

Design

20

20%

Code implementation

40

60g

Test

10

10%

Analysis Summary

20

20%

Experiment Content One:

Enter the CD Code command to enter the code (note C to capitalize) directory

Enter the mkdir 20135127 command to set up the experiment directory, using the LS command or the dir command to view the established directory situation.

Enter the CD 20135100 command into the experimental directory, and then enter a similar mkdir EXP1 to establish the first experimental directory, and then enter the CD EXP1 into the experimental directory, you can enter the PWD command to view the current working path,

Enter Gedit Hello.java, enter the code, and save it in the EXP1 directory

Enter javac-d. Hello.java command to compile the code, enter the Java LJP. The Hello command runs the program.

Do not find the file here, but I stored it in the EXP1.

Found when-D. Is the space does not hit the reason, now can run normally.

Experiment Content Two:

Java program development and debugging under Eclipse

In Eclipse, click File->new-> Java Project to create new Java projects,

Enter the project name Hellojdb and click the Finish button to complete the new project.

In Eclipse, click File->new->class to create a new Java class,

According to the Java Code specification, enter the package name LJP (lowercase, can be customized), the class name Hellojdb (the first letter of the word), and tick the Automatically generate main function option, and then click the Finish button,

Click the Run button (or use the CTRL+F11 shortcut key) to see the results of the run in the console.

To practice the debugger, first we open the Debug view by clicking Window->open perspective->debug

The debugger first sets breakpoints and runs in one step.

Set a breakpoint right-click on the line, toggle Breakpoint

Single-step Operation Press F6

Then click the Debug button (or use the F11 shortcut) to start debugging the Java program, and we can see that the program stays on line 4th,

To set a conditional breakpoint, we right-click on the left side of line 11th and select Breakpoint Properties ...

We set the condition "i==50"

Click F8, we can see that I is 50.

Experiment Content Three:

Realization of four meta-calculation

import Java.util.Scanner;

class count0412

{

Public  Static Double count (double A,int B,double c)

{

double sum=0;

Switch (b)

{

Case 1:

Sum=a+c;

break;

Case 2:

Sum=a-c;

break;

Case 3:

Sum=a*c;

break;

Case 4:

SUM=A/C;

break;

}

return sum;

}

}

Public class Count {

Public Static void Main (string[] args) {

int flag=1;

double A;

int b;

double C;

Do {

System. out. println ("Please enter a number:");

Scanner S = new Scanner (System. in);

A = S.nextdouble ();

System. out. println ("Please select operation symbol + (1),-(2), * (3),/(4)");

b = S.nextint ();

System. out. println ("Please enter a number:");

c = s.nextdouble ();

if (C==0 && b==4)

flag=0;

Else if (b!=1 && b!=2 && b!=3 && b!=4)

flag=0;

}while (flag==0);

count0412 sum=New count0412 ();

System. out. println (sum. Count(A, B, c));

}

Problems encountered in the experiment:

1. In the operation, it is necessary to enter a symbol, which requires the storage of character type.

2. How to achieve effective cycle judgment.

3. This program actually has a problem, when the input conditions are not satisfied, for example, divided by 0, or enter the wrong operation symbol, will require re-input, but re-entered the correct content does not overwrite the error, resulting in a dead loop.

Workaround:

1. I check online, you can use a = S.next () chrat (0), this statement entered a single character, but the actual operation, the first number after the stop input space entered, resulting in the program into the interminable cycle Orz, did not think of a good solution, stole a lazy, The four symbols are replaced with 1,2,3,4 four digits, which implements the input.

2. Using the Do-while statement, it is very appropriate to perform a re-judgment first. Set up a flag, to judge, is the habit of using C language before.

3. Do not understand the Java input statements, on-line check, temporarily did not find a solution, in the later study will improve the program.

Java Experiment One 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.