First Java Lab report

Source: Internet
Author: User

Java Lab Report

20135226 Kun Huang

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

Java program development and debugging under Eclipse

In Eclipse, click file->new-> Java Project, enter the project name HELLOJY, and click the Finish button to complete the new project, and in Eclipse, click file->new-> Class new Java class

According to the Java Code Specification input package name JY (lowercase, can be customized), the class name Hellojy, and tick the Automatically generate main function option, and finally click the Finish button. Enter the 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);

}

}

}

(iii) problems encountered and solutions

No

First Java Lab report

Related Article

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.