Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
Java (not to be confused with JavaScript) is a class-based, object-oriented, strongly typed, reflective language and run-time environment (JRE). Java programs are compiled to bytecode and run in a virtual machine (JVM) enabling a "write once, run anywhere" (WORA) methodology.
3
votes
Accepted
split items of batch into multiple categories
Your Collector is reinventing the wheel. There already exists a collector which partitions the collected items into groups: Collectors.groupingBy, which you could use something like:
.collect(
C …
5
votes
Accepted
In Java: convert an array of floats to bytes and vice versa
Your code is way more verbose than it needs to be.
First of all, BYTES_PER_FLOAT is unnecessary. You could simply use Float.BYTES, a built-in constant.
Secondly, the initial ordering of a ByteBuffer …
1
vote
Getting point on a rectangle border
Most rectangles have a length and a width. I’ve never heard of a rectangle with a radius, but it would be known as a square.
More constructively:
System.out.print(String.format("(%d,%d) ", x - r + …
2
votes
Calculating the Factorial of a number
static
The Factorial class doesn't have any non-class data members, so it shouldn't have any non-static methods.
In particular:
getFactorialWithLoop() can be made static.
getFactorialWithRecursion …
1
vote
Refactor multiple if statements while creating object
Your HelperService.toRefactor() doesn't seem to be accessing any data in its own HelperService instance, so it probably should be a static method.
Your "ideal" solution would not work well, since i > …
3
votes
Efficient way of BinaryGap
Unused Imports
import javax.swing.plaf.basic.BasicInternalFrameTitlePane.MaximizeAction;
This is never used, so why have it?
Useless Comments
// TODO Auto-generated method stub
Clearly, you've …
5
votes
Java code for scoring bowling
BowlingFrame and Roll contain unused information. frame.roll1.isSpare and frame.roll2.isStrike are never used. It would make more sense for isStrike and isSpare to be members of BowlingFrame, at whi …
4
votes
Split List<String[]> into List<List<String[]>>
Low hanging fruit
l1 and l2 are very opaque variable names. start_indices and end_indices would be much more descriptive.
//get all position of 3000
List<Integer> l1 = IntStream.rang …
4
votes
Check if time intervals overlap using integers
Bugs
rangePeriod1 = IntStream.range(startPeriod1 + 1, endPeriod1).boxed().collect(Collectors.toList());
Consider the period from 2 until 4. It fully encompasses 2:00-2:59 and 3:00-3:59. How …
1
vote
Grade Statistics
Bug
Your "Part 2" needs work. Specifically, the requirement is
If there are no numbers giving a passing grade, the program should print a line "-" where the average would be."
Your program crashes i …
3
votes
How can I optimise my code with BufferedInputStream
It was hard to get the exception handling & closing of files correctly written, until Java 1.7's try-with-resources statement. …
2
votes
Given an array return true if can be splitted to two groups with same number of cells and sa...
Trivial Rejects
You are missing some easy checks which can rapidly yield a false result. First, if a.length is not even, you cannot divide the array into two evenly sized groups. Second, if \$\sum a …
5
votes
Accepted
Tic-Tac-Toe in Java with GUI
Event Dispatching Thread
Since Swing is not thread safe, all Swing UI component creation and modification should be done on the Event Dispatching Thread (EDT). It isn’t a problem with this program, …
4
votes
Accepted
Roman Numbers in Java
Magic Numbers
From main(), we can see getInput() returns 1 or some other value. What input does getInput() get? What does 1 mean? What is the other value?
Consider using named constants, such as: …
4
votes
Accepted
Optimal change with only with two euros coins and five and ten euros bills
The only way of making an odd total is with a five euro bill. There is no point ever having more than 1 five euro bill, as you could replace pairs with a ten euro bill. So, you should start off chec …