DevJourney · code I wrote while learning

README.md

4.6 KB

CAT-2 Java assessment programs

Each source is an independent program with class Main. Copy the selected source to Main.java if your lab IDE requires that filename. Do not compile these sources together. See the course index for compilation commands and import scope.

Input formats

NumberProgramInput
01Boothm q
02Euclida b
03Karatsubax y
04Longest ones after flipping bitone integer
05Swap nibblesone byte value
06Block swapn d, followed by n array elements
07Max product subarrayn, followed by n elements
08Maximum hourglass sum36 integers for a 6x6 matrix
09Max equilibrium sumn, followed by n elements
10Leadersn, followed by n elements
11Majority elementn, followed by n elements
12Lexicographically first palindromic stringone string

See EXPLANATIONS.md for algorithm notes, exact numeric domains, and input/output examples.

Output and numeric domains

Every program prints one result and never prompts. These contracts are exact; the code does not silently wrap a valid input.

NumberOutput and numeric domain
01Signed 32-bit m q; prints the exact signed 64-bit product, including MIN_VALUE * MIN_VALUE.
02Signed 64-bit a b; prints the exact nonnegative gcd. The gcd 2^63 prints 9223372036854775808.
03Signed 64-bit x y; prints the exact arbitrary-precision product, including products beyond 64 bits.
04One signed 32-bit bit pattern; prints 0..32 using at most one zero-bit flip. -1 prints 32.
05Only the low eight bits of the integer are used; output is in 0..255.
06n >= 0, any signed 32-bit d; left rotation, negative d rotates right, n = 0 prints nothing.
07n >= 0, signed 64-bit elements; exact arbitrary-precision product; n = 0 prints 0.
0836 signed 32-bit cells; exact 64-bit hourglass sum.
09n >= 0, signed 64-bit elements; exact prefix sums. No equilibrium prints 0, which is ambiguous with a valid sum of 0.
10n >= 0, signed 32-bit elements; equal values may all be leaders.
11n >= 0, signed 32-bit elements; no majority prints -1, which is ambiguous when -1 is the majority.
12One nonempty Unicode token; prints the lexicographically first palindrome or Not possible.

FAT preparation also uses these CAT-2 topics. Use these files instead of duplicate downloads. See FAT programs for the additional topics.