Using the Java language in ACM

Source: Internet
Author: User

One

Each language has its own merits, and when it comes to ACM, if you use Java for beginners, you may want to note several things:

1, the Java code to commit to the main class name.

2, because the main method in the primary class is the public static void type, the methods and variables used inside are also static types, and in addition, they can be invoked by instantiating an object.

public class Main

{

...

void f (int a)

{

...

}

public static void Main (String args[])

{

...

Main m= new Main ();

M.F (1);

...

}

}

3, using structs in Java, you can define a different class instead, and you can add a few methods.

Class good

{

int price;

int weight;

...

}

However, it is important to note that the main class should be placed on the first of all classes at the time of submission, otherwise there may be some problems.

4, there are a number of functions in C/C + + and there are methods in Java that correspond to them.

memset,qsort/sort and bsearch:

Arrays.fill ();

Arrays.sort ();

Arrays.binarysearch ();

5, in Java, Boolean type is Boolean, only true and false two values, in the if (...)/while (...) statements such as the conditions must be The Boolean type.

So the if (n% 2) in C + + ... cannot be compiled in Java .

Two

It's easy to use Java in some places when you're doing a problem.

1, the scanner class in Java has a good support for doing the problem.

Scanner in=new Scanner (system.in);

2, the use of BigInteger and BigDecimal class is also very good in the large number of questions!

Using the Java language in ACM

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.