20135236 Experimental Reports

Source: Internet
Author: User

Java Lab Report

20135236 Jia

First, the contents of the experiment

(i), command-line Java program Development

(ii), under Eclipse Java program development, debugging

(iii) Implementation of arithmetic and testing via command line and Eclipse two methods

Second, the experimental process

(i) Java program Development under command line

Open the terminal (like cmd in Windows), then run the shell program automatically, enter the CD Code command into code (note C to capitalize) directory.

Enter the mkdir 20135236 command to set up the experimental directory, you can use the LS command or the dir command to view the established directory situation.

Enter the CD 20135236 command into the experimental directory, and then enter a similar mkdir EXP1 to create 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 or vim Hello.java, edit Hello.java.

Enter javac-d. Hello.java Command Compile code, enter java JY. The Hello command runs the program.

Results of the output

(ii), under Eclipse Java program development, debugging

      in eclipse new java project, enter project name hellojy Span style= "font-family: ' Times New Roman ';" >finish button to complete the new project, in file-> New->class java

According to Java Code Specification input package name jy(lowercase, can be customized), class name hellojy, and tick the automatically generate main function option, and finally click the Finish button. Input Code

Package hellojy;

public class Hellojy

{

public static void Main (string[] args)

{

int i = 5;

int j = 6;

int sum = Add (i, j);

SYSTEM.OUT.PRINTLN (sum);

sum = 0;

for (i=0; i<; i++)

sum + = i;

SYSTEM.OUT.PRINTLN (sum);

}

public static int Add (int augend, int addend)

{

int sum = augend + addend;

return sum;

}

}

Set breakpoints

(iii) Implementation of arithmetic and testing via command line and Eclipse two methods

Package Perform;

Import Java.util.Scanner;

public class Perform

{

public static void Main (string[] args)

{

Scanner i= New Scanner (system.in);

System.out.println ("Enter the first number");

Double A = i.nextdouble ();

SYSTEM.OUT.PRINTLN ("input operator");

String s = i.next ();

System.out.println ("Enter a second number");

Double b = i.nextdouble ();

if (s.equals ("+"))

{

Double sum;

Sum=a+b;

SYSTEM.OUT.PRINTLN ("Result:" +a+s+b+ "=" +sum);

}

else if (s.equals ("-"))

{

Double sum;

if (a<b)

{

Sum=b-a;

SYSTEM.OUT.PRINTLN ("Result:" +a+s+b+ "=" +sum);

}

else if (a>b)

{

Sum=a-b;

SYSTEM.OUT.PRINTLN ("Result:" +a+s+b+ "=" +sum);

}

}

else if (s.equals ("*"))

{

Double sum;

Sum=a*b;

SYSTEM.OUT.PRINTLN ("Result:" +a+s+b+ "=" +sum);

}

else if (s.equals ("/"))

{

if (a<b)

{

Double sum;

sum=b/a;

SYSTEM.OUT.PRINTLN ("Result:" +a+s+b+ "=" +sum);

}

}

else if (a>b)

{

Double sum=a/b;

SYSTEM.OUT.PRINTLN ("Result:" +a+s+b+ "=" +sum);

}

}

}

implemented with Eclipse

Implemented with the command line

(iii) problems encountered and solutions

1, in the experiment one, to enter the javac-d. The Hello.java command compiles the code. The two spaces after-D are ignored, resulting in an inability to compile.

FIX: Enter code format correctly

2, in the experiment two, set the breakpoint has been in the public class Hellojy here interrupt can not modify the value of the following i

Solution: not yet solved.

20135236 Experimental Reports

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.