Tagged Questions
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 byte-code and run in a virtual machine (JVM) enabling a "write once, run anywhere" (WORA) methodology.
16
votes
1answer
2k views
Weekend Challenge - Poker Hand Evaluation
Weekend Challenge #2 - Poker Hand Evaluation
Very early I decided to support the usage of wild jokers, even though I knew that this was going to lead to trouble more work. I also wanted to support ...
7
votes
4answers
2k views
Sound manager for Android
I created a singleton class for managing sound effects on Android. This class will only be instanced and loaded once at the beginning, and each activity will use the loaded songs.
I don't know either ...
27
votes
3answers
795 views
Analyzing Minesweeper Probabilities
Calculating probabilities in Minesweeper might sound like an easy task, but I've seen so many probability calculators that's either incorrect, horribly slow, or with ugly code (or all of them) so I ...
4
votes
3answers
279 views
Readable code with many components (Swing)
Please help me to make more readable and simple code like this. What if I had 20 components? Is it right to organize code like this?
...
64
votes
8answers
11k views
'100' is a magic number
Magic numbers are bad... I totally agree. But there's one magic number I find hard to fix:
'100' is a magic number.
Consider this code:
...
26
votes
2answers
419 views
Tool for creating CR questions
To download the tool and for usage instructions, see the follow up to this question
Description
I have realized that there's a whole bunch of code I want to have reviewed, but copying file by ...
13
votes
1answer
588 views
Recursive and flexible approach to Tic-Tac-Toe
Description
This is my code for the Weekend Challenge Reboot - Tic Tac Toe Ultimate.
The game can be played here: http://www.zomis.net/ttt (along with some other variations that are also use the ...
6
votes
4answers
5k views
Random walk on a 2D grid
The program assignment:
A drunkard in a grid of streets randomly picks one of four directions
and stumbles to the next intersection, then again randomly picks one
of four directions, and so ...
41
votes
4answers
5k views
Ternary operation in Java - isn't this abuse?
I think the below code is difficult to understand. I also feel it abuses Java's ternary operator.
...
27
votes
8answers
15k views
Efficiently checking if a number is divisible by 3
I'm looking for code review, best practices and optimizations.
...
7
votes
3answers
604 views
16
votes
1answer
203 views
Follow-up to tool for posting CodeReview questions
Description
This is a follow-up question to Tool for creating CR questions.
Things that has changed include:
Removed replacing four spaces with one tab, all tabs and all spaces in the code itself ...
12
votes
7answers
876 views
Quadratic expression calculator
I'm hoping to get some feedback on how to improve and optimise a program I wrote which takes three values as input (via the terminal) and uses them in the quadratic formula.
I'm aware this is mostly ...
8
votes
3answers
201 views
task with GregorianCalendar
I have to create a class Data with date, there should be some method and constructor. Can you check it? Maybe some method can be done in another way, especially ...
9
votes
1answer
72 views
YAuB - Micro Benchmark Follow-on
Following some great advice here from Simon, I realized that I had over-engineered things, and that the Task builder methods were a horrible Java8 abstraxction. In Simon's words: "From a usability ...
9
votes
2answers
727 views
Simple calculator that seems inefficient
I have a simple calculator program that needs some reviewing. Is this as efficient as it can get, or is there a better way?
...
7
votes
3answers
1k views
Converting a number to the text representation
Following along with some previous questions:
The @dbasnett original here: Number to Words
@nhgrif's here: Int extension for translating integer to plain English
I wanted to answer the original ...
6
votes
3answers
596 views
Project Euler Problem 12 - triangle number with 500 divisors
I've just done Problem 12 of Project Euler:
What is the value of the first triangle number to have over five hundred divisors?
The \$N\$'th triangle number is the sum of all natural numbers ...
6
votes
3answers
324 views
Optimizing unique partitions of integers
I am working on a project involving the unique partitioning of integers. I.e. I am looking to have all of the partitions of n = x1 + x2 + x3 + ... + xk, where xi = xj implies i = j.
For example, if I ...
3
votes
1answer
207 views
How to avoid making the call to the servers whenever it is down?
I am working on a project in which I construct a url with a valid hostname (but not a blocked hostname) and then execute that URL using RestTemplate from my main ...
17
votes
3answers
4k views
TicTacToe logic in Java
I'm currently studying Java by myself. The book I'm using (while very good)
lacks feedback (obviously). While trying to write this program, I found myself solving most of the problems I've ...
31
votes
5answers
2k views
7
votes
3answers
663 views
How to simplify a program that takes in the compulsory courses and returns a list of ordered (in the way they need to be taken) courses?
I recently graduated from college and applied for a position with a company. I was sent a coding exercise as part of the process. After completing the exercise and submitting it I was told that the ...
27
votes
8answers
3k views
The FizzBuzz challenge in Java 8 written in a short, readable and interesting way
I decided to take on the FizzBuzz challenge with as twist that I would use Java 8 concepts to make it a bit modular, yet still let it be a short, readable and understandable program.
This in contrary ...
12
votes
3answers
319 views
N-Queens - Brute force - bit by bit
A discussion in The 2nd Monitor made me realize I had never 'solved' the N-Queens problem. Additionally, as I read up on it, I realized that the 64-squares in a chess board would work well if ...
11
votes
3answers
19k views
Simple Java animation with Swing
I am learning to use Java Swing and have made a simple animation that makes a small shape bounce around the predetermined borders of a panel. The program works well, but I am looking for feedback in ...
10
votes
3answers
155 views
Simple micro-benchmarking library
I'm working on a simple micro-benchmarking library in Java.
This library makes it easy to benchmark multiple reference implementations.
You provide the inputs and trigger the calls,
the library takes ...
21
votes
7answers
4k views
Finding words of different lengths given six letters
I'm trying to find all the 3, 4, 5, and 6 letter words given 6 letters. I am finding them by comparing every combination of the 6 letters to an ArrayList of words ...
17
votes
5answers
6k views
Tic Tac Toe computer AI
I am creating a TicTacToe game for my college project, and when I finished the code for computer AI, I ended up with a big chunk of code.
It allows the computer to make the winning move, stopping the ...
15
votes
7answers
9k views
Check for balanced parentheses
Given an expression string exp, write a program to examine whether the
pairs and the orders of
"{","}","(",")","[","]"
are correct in exp.
For ...
14
votes
4answers
709 views
Determining if an answer can be generated
How can I improve my code below for the following question? While it works, I am not satisfied with how it looks; I was hoping I can somehow keep it recursive, and have the ans filled up inside the ...
21
votes
3answers
284 views
Advanced and Detailed Minesweeper Probabilities
In an earlier question, I showed my code for calculating the mine probability for each and every field in a Minesweeper board. But it doesn't stop there. In that very same Minesweeper Analyze project, ...
17
votes
7answers
8k views
Cleaning up multiple if statements
I have a method like the below and want to clean it up as it does not read well and is difficult to follow.
The objective of the method is to determine which Block name should be used further in the ...
11
votes
5answers
2k views
Using sounds in Java
I'm trying to apply sound today, and the goal in mind was a simple violin tuner. The actionListener seems repetitive/ How might I optimize it (what I tried just ...
10
votes
5answers
1k views
Prime Number Sieving Algorithm
Last semester in my Masters Program I developed this code for sieving. My professor wants me to write a report that he might use locally within the school, but I feel like I've done nothing that new, ...
10
votes
2answers
1k views
Missing level of technical depth (Common Ancestor)
I recently have given a coding test in a reputable IT company. There were three coding questions.
They refused me by saying that
as we felt they didn't demonstrate the level of technical depth ...
3
votes
2answers
4k views
Optimizing mass inserts into SQLite
I am trying to optimize inserts from a returned JSON which contains data from multiple tables on the remote server. My code is working, but I just want to figure out a way for it to work better. I ...
20
votes
2answers
2k views
A grid and a menu walked into a program
A program that creates a grid 10x10 and assigns a random number in each tile. It then asks you if you want to:
create a new grid
view the current one
count how many of each number there are in the ...
15
votes
1answer
2k views
Project Euler “Even Fibonacci numbers” in Java 8
I'm looking for general advice on my code on the following problem:
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 ...
13
votes
2answers
507 views
It's Friday! - Zeller's Congruence Revisited
A couple of date-related questions have come up recently, and on both occasions I have been taken back to my 'early' days where one of my first forays in to programming involved implementing Zeller's ...
12
votes
6answers
4k views
Optimize Conway's Game of Life
I have coded up an implementation of Conway's Game of Life and I have a performance bottleneck in it which I wish to be optimized. The main logic is in the Universe ...
11
votes
2answers
2k views
Rock Paper Scissors Lizard Spock as a code-style and challenge
The following is a program that lets a Human play "Rock Paper Scissors Lizard Spock" against the computer... (almost playable at: http://ideone.com/EBDlga)
Note I have posted a follow-up question ...
10
votes
3answers
386 views
Match Simple Sentence or Partial Sentence
Description
Match a Simple Sentence or a partial sentence
Suitable for matching
People Names (to some extent)
Product Titles (to some extent)
Correct use of apostrophe (to some extent)
...
10
votes
2answers
909 views
Guess a random number between a selected interval
My project for my class is to create a Java-based game where the user must enter a number between 1-20 and a number between 250 and 300. The computer randomly chooses a number between those 2 numbers. ...
9
votes
3answers
398 views
The Beauty and the Strings
This originally appeared in Facebook's hacker cup 2013. Solving it was fun, though I find myself looping through similar data quite often.
Challenge:
Print the maximum beauty of strings.
...
8
votes
4answers
965 views
Align Strings for Output
I wrote a class which can format input so that it is properly aligned.
I'm interested in all suggestions (regarding structure, usability, style, naming, comments, etc).
I'm especially wondering ...
8
votes
1answer
470 views
Java application for finding permutations efficiently
I am an eighth grader with a school project of creating and application in Java that returns the total permutations of two given numbers. It needs to be light and efficient, for later deployment on a ...
7
votes
2answers
500 views
Kruskal's algorithm in Java
I have this Java implementation of Kruskal's algorithm. It solves a tiny problem instance correctly, yet I am not quite sure, whether my implementation is correct.
The code as follows:
...
7
votes
1answer
604 views
Generic Java task-scheduler
I wrote this generic task scheduler for executing tasks in fixed-delay intervals. Can you find anything wrong with it, or issues that may arise from using it for sending something like queued mails in ...
7
votes
1answer
255 views
Latency problem for keyboard remoting from Android phone
I'm writing a simple remote PC app (mouse-keyboard). Android is client and is connect with WiFi to Java PC Server. I'm using TCP but I see a bit of latency compared to other remote apps. Then I used ...