CJCoding With Joseph
15per day

Custom RuntimeException

Build a stock-checking system:
1. Create a class OutOfStockException that extends RuntimeException. Its constructor takes a String item name and passes "Out of stock: " + item to super.
2. Write a method checkStock(String item, int qty) that throws OutOfStockException if qty is 0.
3. In main, read an item name and quantity. Call checkStock, print "In stock" if no exception, or print e.getMessage() if caught.

⚠️ AUTO-INPUT MODE: The input stream will automatically contain 'apples 0\n'.

Expected Output:

Out of stock: apples
Topics:
Miscellaneous
📥 Auto-Input:
apples 0\n
This input is automatically fed to your program's stdin
Code Editor
1
Tab to indent · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.