Questions tagged [java]
This challenge is related to the Java language. Note that challenges that require the answers to be in a specific language are generally discouraged.
44
questions
-2
votes
1
answer
200
views
Comparator function in Javascript [closed]
Need to write a JS function compare(a,b) for numbers which return
1 when a > b, 0 when a == b, -1 when a < b.
Also following properties should hold:
compare(NaN, NaN) = 0
NaN is bigger than any ...
21
votes
17
answers
2k
views
King of The Holster (finished)
CLOSED to competing entries
New bots are welcome but are not part of the main competition and probably won't be officially tested.
You stand on a dusty stretch of code, watching the other programs ...
1
vote
2
answers
571
views
Hash bomb filtrate
Pipe a short stream to the following Java program run with accompanying command line options, such that it prints true.
...
-6
votes
2
answers
414
views
Fastest N times Hello World (Java/C/ C++) [closed]
Not a new one:
Input
N, being n, 0 ≤ n ≤ 5.
Output
N times "Hello World."
Example:
Input
3
Output
Hello World.
Hello World.
Hello World.
These 2 are my ...
3
votes
4
answers
498
views
Intercommunication between threads [closed]
So glad I found this cool site. Wanted to try sharing a coding challenge a friend gave me, an interview question. Usually it is written in java, but you can use whatever language you want, just have ...
33
votes
30
answers
8k
views
Dollar Bill Auction
This is a KOTH challenge for the dollar bill auction game in game theory. In it, a dollar is being sold to the highest bidder. Bids go up in increments of 5¢, and the loser also pays their bid. The ...
37
votes
4
answers
3k
views
Splix.io - King of the land
You are an enterprising dot who wants to increase the land under its control. This is quite simple - travel outside your current land and loop back into your land and everything in that loop is now ...
5
votes
0
answers
277
views
Golf this AP CS Java FRQ - Duplicate Sums of Arrays in 2D Array [closed]
In preparation for the AP Computer Science AP Test (Java), our teacher has been giving us FRQs from previous years for practice.
My friend and I were golfing this during class today and got it as ...
5
votes
1
answer
807
views
Minesweeper Wars [closed]
We've had problems to generate minesweeper games.
We've had problems to solve these minesweeper games.
Now...
It's time to battle other people on a minesweeper game!
Your program must be run in Java....
-3
votes
2
answers
654
views
Shortest program to throw NullPointerException in Java
I find NullPointerException to be interesting since there are no explicit pointers in Java. Here is a program that throws such an exception.
...
-3
votes
2
answers
3k
views
Checking String for enum in Java [closed]
Write a Java method to check if a given string matches any value in a given enum.
Your method will take two parameters, one a string and one an enum, and return ...
45
votes
19
answers
2k
views
Battle of the Fellowships KotH
In this challenge, you are going to create a Fellowship with the goal of defeating all other fellowships in battle.
A fellowship (team) consists of 3 characters. Each character moves independently ...
16
votes
4
answers
2k
views
Java Asterisk Rectangle
For my CS class, my instructor has given us the assignment of creating a rectangle made of asterisks with diagonal lines drawn through it in Java.
He also told us to write it in as few bytes as ...
4
votes
3
answers
677
views
King of the Torus!
King of the Torus!
Your job is to conquer the torus, but wait, there are multiple other players banded together in teams facing you! You will need to use your wit's to conquer the torus.
There are ...
3
votes
1
answer
832
views
Translate Java methods to fields
So, recently, I found myself reformatting my code for Vitsy to using anonymous class instances for commands rather than the normal method approach. For those who don't know, anonymous class instance ...
23
votes
7
answers
5k
views
King-Pen! (Dots and Boxes)
This is a king of the hill challenge for Dots and Boxes (aka Pen the Pig). The game is simple, on your turn just draw a line on an empty fence. Every time you complete a square you get a point. Also, ...
25
votes
14
answers
2k
views
Code Bots 4: Functional Programming
sheesh, is this really the 4th? For all you oldcomers, the core challenge is the same, but we are using Java instead of a custom language. Here are the past three CodeBot challenges, in case you are ...
19
votes
12
answers
2k
views
Connect-n time!
https://en.wikipedia.org/wiki/Connect_Four
Does anyone remember the 2 player game connect 4? For those who don't it was a 6x7 board that stands vertical on a surface. The goal of connect 4 is to, ...
50
votes
28
answers
9k
views
You are the Weakest Link, Goodbye
This king-of-the-hill challenge is based off of the game show, Weakest Link. For those unfamiliar with the show, the crux of this challenge deals with who you vote off:
If the other players are ...
18
votes
10
answers
2k
views
Coin Tossing Time Travelers
In the future when Time Travel (abbreviated as TT) will be common, coin tossing will become a serious mind-sport. To prepare for the future we create a competition for programs where time traveling ...
5
votes
5
answers
1k
views
Remove Whitespace from a Java Program [closed]
In this challenge, you will be given the source code of a Java program. Your task is to write a function or full program that will remove the whitespace from this program. The whitespace-removed ...
10
votes
4
answers
3k
views
What is the shortest infinite loop statement in Java?
I'm working on a golf for Java and I need an infinite loop. Obviously, I don't want to spend any more bytes than I have to, especially in such an expressive language.
Assuming I have some code I want ...
7
votes
0
answers
859
views
Tricky interview puzzle: get longest sequence by flipping 1 bit [closed]
A friend of mine got this question during an interview.
The interview ended with no luck for him, but still, we're very curious to hear the solution. The question is as follows:
Modify the code below ...
12
votes
5
answers
2k
views
Risk, the Warlight Way
Introduction
In this game, players use their armies to fight other players' armies, capture territories, and become the last man standing. Each turn, players receive a base number of armies to use at ...
11
votes
11
answers
1k
views
Rocket Bots KOTH
Rocket Bots
The year is 3024. People have become too scarce a resource to risk in war, so combat has shifted to the robots. Your task is to construct a bot like no other, who's rockets will rain ...
12
votes
7
answers
1k
views
Simple Pazaak (Star Wars Card Game from Knights of the Old Republic)
Pazaak is a card game from the Star Wars universe. It is similar to BlackJack, with two players pitted against each other trying to reach a total of twenty without going over. Each player has a "side ...
22
votes
9
answers
3k
views
King of the Hill - Liar's Dice
Liar's Dice is a fairly simple dice game. I've seen a few different variations of the rules, but here is the version I'm most familiar with:
Each player starts with 5d6
Except when tallying the dice ...
22
votes
12
answers
1k
views
The Great Wumpus Hunt
COMPLETE
Wumpus season has ended, and with, the lives of many a vicious Wumpus and brave Hunter. As well as some cowardly, immoral and downright stupid Hunters. But at the end of the day, ...
18
votes
9
answers
1k
views
Asymmetrical KOTH: Catch the Cat (Catcher Thread)
UPDATE:
The gist-files are updated (including new submissions) as the Controller.java did not catch Exceptions (only errors). It does now catch errors and exceptions and also prints them.
This ...
15
votes
9
answers
1k
views
Asymmetrical KOTH: Catch the Cat (Cat Thread)
UPDATE:
The gist-files are updated (including new submissions) as the Controller.java did not catch Exceptions (only errors). It does now catch errors and exceptions and also prints them.
This ...
37
votes
20
answers
4k
views
Strategic Voting, The Game
One of the most common voting systems for single-winner elections is the plurality voting method. Simply put, the candidate with the most votes wins. Plurality voting, however, is mathematically ...
0
votes
2
answers
402
views
Java Package Correction
I have a lot of java projects and I am often making new ones. I have a few helper classes (Vector, Logger, etc.) and it takes a lot of time correcting the first line to the correct package, I would ...
6
votes
7
answers
1k
views
King of the Hill: Robot Battle
Your task here is to write an AI for a simple robot battle. The class to be implemented is provided at the bottom of this post, and source of the controller can be found here.
Requirements
Write a ...
31
votes
6
answers
5k
views
That's BS! (card game)
BS is a card game where the object of the game is to lose all of your cards.
A game consists of four players and a 52-card deck. Each player is randomly dealt 13 cards. Normally, cards are labeled 2 -...
12
votes
8
answers
1k
views
Water Balloon Wars
This king-of-the-hill game is a strategy game in which you must throw around a water balloon and avoid getting splashed by water. The goal is to obtain the most points. You will be given a map of the ...
21
votes
8
answers
26k
views
Shortest code to throw IllegalArgumentException in Java
Okey, we all know the normal way to throw a IllegalArgumentException in Java:
throw new IllegalArgumentException(); // 37 characters
But there must be a shorter (...
23
votes
9
answers
3k
views
Chess Tournament
This is a chess-KOTH with simplified rules (because chess itself is already complicated, playing it via a simple program doesn't make it easier). At the moment it is limited to java (version 8), but ...
97
votes
44
answers
11k
views
Survival Game - AlienWar
AlienWar
This game takes place in a very crowded planet where aliens are the superior race. Your task is to create your own alien and beat all other.
The Board
It is a 2 dimensional board.
The ...
18
votes
6
answers
2k
views
reach catch when everything in the try block is caught already
This is limited to Java and C# by the syntax I guess.
In this programming puzzle, you are to produce Exceptions that can be caught but are thrown again at the end ...
247
votes
56
answers
55k
views
Survival Game - Create Your Wolf
The Board
The Board is a two dimensional array of cells. Cells are populated by Animals. Every day, all Animals on the Board simultaneously make one move. If two or more Animals move to the same cell, ...
3
votes
1
answer
859
views
Flip the commented-out code [closed]
This puzzle works for any programming language that has the same // single-line and /* ... */ multi-line comments that C++, C# ...
-2
votes
3
answers
10k
views
Write a program to print squares of integers up to 25 in java without using variables? [closed]
I asked this question on programmers 10 days back but wasn't able to get the answer that I wanted.
Write program in java to print the squares of first 25 integers(1-25) without using any variables.
...
16
votes
3
answers
2k
views
Write a java code to detect the JVM version
The objective is to write java code that detects the JVM version relying in compatibility changes, side effects, bugs and/or undefined behavior that works in a way in one version and another way in ...
106
votes
39
answers
27k
views
Tips for golfing in Java
Are there any useful shortcuts that can be used in Java?
As shown below, import already adds at least 17 characters to a program.
...