Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Extract More Methods

Right now you have a lot of code in the main method. Ideally, you want to split up your code and have many methods each only doing one thing.

Naming Conventions

Class names should always start with a capital letter! (UpperCamelCase)

Pick more meaningful names. You're using a lot of one-character variable names, try not to do that. (It's okay for loop counters though).

Nested Assignments

You have the following:

input.add(in = Integer.parseInt(br.readLine()));

Don't use these nested assignments. "While admirably terse, such expressions may be confusing, and violate the general design principle that a given construct should do precisely one thing."

Braces

Always use braces for if-statements and loops. It just makes them that much more readable.

Unnecessary code

In your main method, you have an ArrayList named 'input' that is only written to, but never read from. In other words, you're not using it and you might as well omit it.

You import java.util.Scanner but it is never used. In the Netbeans IDE you can press ctrl-shift-i to automatically sort out imports. I'm sure other IDE's have similar features.

Misc

Don't use System.out.println() if you can avoid itDon't use System.out.println() if you can avoid it.

Make variables final, unless you really need them not to be.Make variables final, unless you really need them not to be.

Code to interface.Code to interface. Save ArrayLists as Lists, for instance. Also, you may omit the diamond brackets as follows:

List<Integer> result = new ArrayList();

instead of:

ArrayList<Integer> result = new ArrayList<Integer>();

Extract More Methods

Right now you have a lot of code in the main method. Ideally, you want to split up your code and have many methods each only doing one thing.

Naming Conventions

Class names should always start with a capital letter! (UpperCamelCase)

Pick more meaningful names. You're using a lot of one-character variable names, try not to do that. (It's okay for loop counters though).

Nested Assignments

You have the following:

input.add(in = Integer.parseInt(br.readLine()));

Don't use these nested assignments. "While admirably terse, such expressions may be confusing, and violate the general design principle that a given construct should do precisely one thing."

Braces

Always use braces for if-statements and loops. It just makes them that much more readable.

Unnecessary code

In your main method, you have an ArrayList named 'input' that is only written to, but never read from. In other words, you're not using it and you might as well omit it.

You import java.util.Scanner but it is never used. In the Netbeans IDE you can press ctrl-shift-i to automatically sort out imports. I'm sure other IDE's have similar features.

Misc

Don't use System.out.println() if you can avoid it.

Make variables final, unless you really need them not to be.

Code to interface. Save ArrayLists as Lists, for instance. Also, you may omit the diamond brackets as follows:

List<Integer> result = new ArrayList();

instead of:

ArrayList<Integer> result = new ArrayList<Integer>();

Extract More Methods

Right now you have a lot of code in the main method. Ideally, you want to split up your code and have many methods each only doing one thing.

Naming Conventions

Class names should always start with a capital letter! (UpperCamelCase)

Pick more meaningful names. You're using a lot of one-character variable names, try not to do that. (It's okay for loop counters though).

Nested Assignments

You have the following:

input.add(in = Integer.parseInt(br.readLine()));

Don't use these nested assignments. "While admirably terse, such expressions may be confusing, and violate the general design principle that a given construct should do precisely one thing."

Braces

Always use braces for if-statements and loops. It just makes them that much more readable.

Unnecessary code

In your main method, you have an ArrayList named 'input' that is only written to, but never read from. In other words, you're not using it and you might as well omit it.

You import java.util.Scanner but it is never used. In the Netbeans IDE you can press ctrl-shift-i to automatically sort out imports. I'm sure other IDE's have similar features.

Misc

Don't use System.out.println() if you can avoid it.

Make variables final, unless you really need them not to be.

Code to interface. Save ArrayLists as Lists, for instance. Also, you may omit the diamond brackets as follows:

List<Integer> result = new ArrayList();

instead of:

ArrayList<Integer> result = new ArrayList<Integer>();
Added hyperlinks to explanation.
Source Link

Extract More Methods

Right now you have a lot of code in the main method. Ideally, you want to split up your code and have many methods each only doing one thing.

Naming Conventions

Class names should always start with a capital letter! (UpperCamelCase)

Pick more meaningful names. You're using a lot of one-character variable names, try not to do that. (It's okay for loop counters though).

Nested Assignments

You have the following:

input.add(in = Integer.parseInt(br.readLine()));

Don't use these nested assignments. "While admirably terse, such expressions may be confusing, and violate the general design principle that a given construct should do precisely one thing."

Braces

Always use braces for if-statements and loops. It just makes them that much more readable.

Unnecessary code

In your main method, you have an ArrayList named 'input' that is only written to, but never read from. In other words, you're not using it and you might as well omit it.

You import java.util.Scanner but it is never used. In the Netbeans IDE you can press ctrl-shift-i to automatically sort out imports. I'm sure other IDE's have similar features.

Misc

Make variables final, unless you really need them not to beDon't use System.out.println() if you can avoid it.

Code to interface.Make variables final, unless you really need them not to be.

Code to interface. Save ArrayLists as Lists, for instance. Also, you may omit the diamond brackets as follows:

List<Integer> result = new ArrayList();

instead of:

ArrayList<Integer> result = new ArrayList<Integer>();

Extract More Methods

Right now you have a lot of code in the main method. Ideally, you want to split up your code and have many methods each only doing one thing.

Naming Conventions

Class names should always start with a capital letter! (UpperCamelCase)

Pick more meaningful names. You're using a lot of one-character variable names, try not to do that. (It's okay for loop counters though).

Nested Assignments

You have the following:

input.add(in = Integer.parseInt(br.readLine()));

Don't use these nested assignments. "While admirably terse, such expressions may be confusing, and violate the general design principle that a given construct should do precisely one thing."

Braces

Always use braces for if-statements and loops. It just makes them that much more readable.

Unnecessary code

In your main method, you have an ArrayList named 'input' that is only written to, but never read from. In other words, you're not using it and you might as well omit it.

You import java.util.Scanner but it is never used. In the Netbeans IDE you can press ctrl-shift-i to automatically sort out imports. I'm sure other IDE's have similar features.

Misc

Make variables final, unless you really need them not to be.

Code to interface. Save ArrayLists as Lists, for instance. Also, you may omit the diamond brackets as follows:

List<Integer> result = new ArrayList();

instead of:

ArrayList<Integer> result = new ArrayList<Integer>();

Extract More Methods

Right now you have a lot of code in the main method. Ideally, you want to split up your code and have many methods each only doing one thing.

Naming Conventions

Class names should always start with a capital letter! (UpperCamelCase)

Pick more meaningful names. You're using a lot of one-character variable names, try not to do that. (It's okay for loop counters though).

Nested Assignments

You have the following:

input.add(in = Integer.parseInt(br.readLine()));

Don't use these nested assignments. "While admirably terse, such expressions may be confusing, and violate the general design principle that a given construct should do precisely one thing."

Braces

Always use braces for if-statements and loops. It just makes them that much more readable.

Unnecessary code

In your main method, you have an ArrayList named 'input' that is only written to, but never read from. In other words, you're not using it and you might as well omit it.

You import java.util.Scanner but it is never used. In the Netbeans IDE you can press ctrl-shift-i to automatically sort out imports. I'm sure other IDE's have similar features.

Misc

Don't use System.out.println() if you can avoid it.

Make variables final, unless you really need them not to be.

Code to interface. Save ArrayLists as Lists, for instance. Also, you may omit the diamond brackets as follows:

List<Integer> result = new ArrayList();

instead of:

ArrayList<Integer> result = new ArrayList<Integer>();
Source Link

Extract More Methods

Right now you have a lot of code in the main method. Ideally, you want to split up your code and have many methods each only doing one thing.

Naming Conventions

Class names should always start with a capital letter! (UpperCamelCase)

Pick more meaningful names. You're using a lot of one-character variable names, try not to do that. (It's okay for loop counters though).

Nested Assignments

You have the following:

input.add(in = Integer.parseInt(br.readLine()));

Don't use these nested assignments. "While admirably terse, such expressions may be confusing, and violate the general design principle that a given construct should do precisely one thing."

Braces

Always use braces for if-statements and loops. It just makes them that much more readable.

Unnecessary code

In your main method, you have an ArrayList named 'input' that is only written to, but never read from. In other words, you're not using it and you might as well omit it.

You import java.util.Scanner but it is never used. In the Netbeans IDE you can press ctrl-shift-i to automatically sort out imports. I'm sure other IDE's have similar features.

Misc

Make variables final, unless you really need them not to be.

Code to interface. Save ArrayLists as Lists, for instance. Also, you may omit the diamond brackets as follows:

List<Integer> result = new ArrayList();

instead of:

ArrayList<Integer> result = new ArrayList<Integer>();