[x**2 for x in scores][x for x in scores if x > 50 and x % 2 == 0]. The and works exactly like in an if statement — both must be true.
i is divisible by both 3 and 5 → print "FizzBuzz"
⚠️ This check MUST come first — otherwise 15 will wrongly print just "Fizz"i % 3 == 0 to check divisibility. Why check 15 first? Because 15 % 3 == 0 is also true, so if you check "divisible by 3" first, 15 would print "Fizz" and never reach the FizzBuzz check.
ord() converts a character to its ASCII number, and chr() converts back. This teaches you how characters are really just numbers under the hood.
chr((ord(c) - ord('A') + shift) % 26 + ord('A'))ord('a') as basedecrypt() — just call encrypt(text, 26 - shift)% 26? Letters loop — after Z comes A. Without modulo, shifting 'Y' by 3 would give ord 91 which is '[', not 'B'. The % 26 keeps the number in the range 0–25, then we add the base (ord('A') or ord('a')) to get back to the right ASCII value.
tens[n//10] and ones[n%10], strip trailing/extra spacesones[n//100] + " Hundred " + recursive call to_words(n%100)tens[4] = "Forty", ones[2] = "Two" → join with a space. But for 40: ones[0] = "" — so you'd get "Forty " with a trailing space. Use .strip() to clean it: (tens[n//10] + " " + ones[n%10]).strip()
deposit() — add to balance, append f"+ ₹{amount}" to self.historywithdraw() — raise ValueError if amount ≤ 0 or amount > balance. On success, deduct and log f"- ₹{amount}"withdraw() call in try/except in the test code so the ₹5000 attempt prints a clean errorstatement() — print owner name, balance, and loop through history to print each transactionself.history.append(f"+ ₹{amount}"). In statement(), loop with for t in self.history: print(t). The starting balance of 1000 is set in __init__ so it doesn't appear in history — only changes do.
stream().filter().map().collect() is Java's equivalent of Python's [x for x in list if condition]. You'll do the same data-cleaning tasks but the Java way.
.filter() + .collect() works.map(x -> x * x) to get squares of all scores.filter(x -> x > 50).filter(x -> x % 2 == 0). Or combine in one: .filter(x -> x > 50 && x % 2 == 0). Both work — the chained version is easier to read.
String.valueOf(i) — converts int to String in Javai % 15 == 0 is the same as i % 3 == 0 && i % 5 == 0. Using 15 is cleaner. String.valueOf(i) converts int 7 to the String "7" — Java won't let you return an int where a String is expected.
char (a primitive type) and you can do arithmetic directly on characters — 'A' + 1 = 'B'. Cast back with (char). This shows how Java's type system works at the character level.
'A' with 'a'c - 'A' = 72 - 65 = 7 → add shift: 7+3=10 → mod 26: 10 → add 'A': 65+10 = 75 = 'K'. That's why "Hello" starts with 'K'. Lowercase is identical, just replace 65 with 97 (which is 'a').
ones[n/100] + " Hundred " + toWords(n%100)
Use .trim() to clean trailing spaces when n%100 == 0(tens[n/10] + " " + ones[n%10]).trim() do for n=40? Trace it.n/100=3 → "Three", then recursive toWords(5) → "Five". For 300: toWords(0) → "Zero" — but we don't want "Three Hundred Zero"! Add a check: if (n%100 == 0) return ones[n/100] + " Hundred"; as the first case in the hundreds branch.
ArrayList<String> for history, throw new IllegalArgumentException() for errors, and toString() for display.
deposit() — add to balance, add "+ ₹" + amount to historywithdraw() — throw IllegalArgumentException("Insufficient funds!") if amount > balancestatement() — print owner, balance, then loop through historyfor (String t : history) System.out.println(t);
.map(), .filter(), and .reduce() are the bread-and-butter of modern web development. Every React component, every API response handler, every dashboard uses these. Master them and 80% of real-world JS data work becomes easy.
.filter() scores ≥ 60.map() each score to a grade string "A"/"B"/"C".map(n => n.charAt(0).toUpperCase() + n.slice(1).toLowerCase()).reduce() to find the total and average of all scores.reduce((sum, x) => sum + x, 0) totals the array — the 0 is the starting value. Chain it: scores.filter(x => x > 50 && x % 2 === 0).map(x => "Score: " + x). In JS, use === (strict equality) not ==.
<span> with a color style — blue for Fizz, red for Buzz, green for FizzBuzz, gray for numbers.innerHTML<button> that runs fizzBuzz() with a different N from an <input>html += `<span style="color:#58a6ff;font-weight:bold">Fizz</span> `. Build the whole string first in the loop, then do ONE innerHTML assignment at the end — this is faster than updating the DOM on every iteration.
charCodeAt() instead of ord(), and String.fromCharCode() instead of chr(). The math is identical — just different method names. After writing it, make it interactive with an HTML input!
'a'.charCodeAt(0) as base.split("").map(...).join("") pattern — this is the JS idiom for processing each character of a stringtext.split("") turns "Hello" into ['H','e','l','l','o']. .map() transforms each character. .join("") puts them back together into a string. This is the standard JS pattern for character-by-character string processing.
oninput event. This is a real feature you'd build for a fintech or banking web app.
Math.floor(n/100) for the hundreds digit<input oninput="document.getElementById('out').textContent = toWords(+this.value)">
The + before this.value converts the string "42" to the number 42if (!Number.isInteger(+n)) return "Integers only!"// or Java's int division. Use Math.floor(n / 100) to get the hundreds digit. n % 100 works the same as in Python and Java.
deposit() and withdraw() — same logic, throw new Error("Insufficient funds!")render() — update DOM elements for owner name, balance, and history list<input id="amt">, deposit and withdraw buttons that call the methods and re-render<p id="err" style="color:red"> when withdraw fails, clear it on successrender(): document.getElementById("balance").textContent = "₹" + this.balance. For history: build an HTML string inside this.history.map(t => "<li>" + t + "</li>").join("") and set it as innerHTML of a <ul>.
if statement — only rows that pass it are returned.
| id | name | city | marks | grade |
|---|---|---|---|---|
| 1 | 'Rahul' | 'Delhi' | 72 | 'B' |
| 2 | 'Priya' | 'Mumbai' | 91 | 'A' |
| 3 | 'Arjun' | 'Delhi' | 38 | 'F' |
| 4 | 'Sneha' | 'Pune' | 85 | 'A' |
| 5 | 'Vikram' | 'Mumbai' | 55 | 'C' |
| 6 | 'Anita' | 'Delhi' | 94 | 'A' |
| 7 | 'Rohan' | 'Pune' | 43 | 'F' |
| id | name | city | marks | grade |
|---|---|---|---|---|
| 1 | Rahul | Delhi | 72 | B |
| ... all 7 rows | ||||
| id | name | city | marks | grade |
|---|---|---|---|---|
| 1 | Rahul | Delhi | 72 | B |
| 3 | Arjun | Delhi | 38 | F |
| 6 | Anita | Delhi | 94 | A |
sorted()). LIMIT restricts how many rows come back — useful for "top 3" or "latest 5" queries.
| id | name | city | marks | grade |
|---|---|---|---|---|
| 1 | 'Rahul' | 'Delhi' | 72 | 'B' |
| 2 | 'Priya' | 'Mumbai' | 91 | 'A' |
| 3 | 'Arjun' | 'Delhi' | 38 | 'F' |
| 4 | 'Sneha' | 'Pune' | 85 | 'A' |
| 5 | 'Vikram' | 'Mumbai' | 55 | 'C' |
| 6 | 'Anita' | 'Delhi' | 94 | 'A' |
| 7 | 'Rohan' | 'Pune' | 43 | 'F' |
| id | name | city | marks | grade |
|---|---|---|---|---|
| 6 | Anita | Delhi | 94 | A |
| 2 | Priya | Mumbai | 91 | A |
| 4 | Sneha | Pune | 85 | A |
| id | name | marks |
|---|---|---|
| 6 | Anita | 94 |
| 1 | Rahul | 72 |
| 3 | Arjun | 38 |
| id | name | city | marks | grade |
|---|---|---|---|---|
| 1 | 'Rahul' | 'Delhi' | 72 | 'B' |
| 2 | 'Priya' | 'Mumbai' | 91 | 'A' |
| 3 | 'Arjun' | 'Delhi' | 38 | 'F' |
| 4 | 'Sneha' | 'Pune' | 85 | 'A' |
| 5 | 'Vikram' | 'Mumbai' | 55 | 'C' |
| 6 | 'Anita' | 'Delhi' | 94 | 'A' |
| 7 | 'Rohan' | 'Pune' | 43 | 'F' |
| MAX(marks) | MIN(marks) |
|---|---|
| 94 | 38 |
| AVG(marks) |
|---|
| 90.0 |
| id | name | city | marks | grade |
|---|---|---|---|---|
| 1 | 'Rahul' | 'Delhi' | 72 | 'B' |
| 2 | 'Priya' | 'Mumbai' | 91 | 'A' |
| 3 | 'Arjun' | 'Delhi' | 38 | 'F' |
| 4 | 'Sneha' | 'Pune' | 85 | 'A' |
| 5 | 'Vikram' | 'Mumbai' | 55 | 'C' |
| 6 | 'Anita' | 'Delhi' | 94 | 'A' |
| 7 | 'Rohan' | 'Pune' | 43 | 'F' |
| city | COUNT(*) |
|---|---|
| Delhi | 3 |
| Mumbai | 2 |
| Pune | 2 |
| grade | AVG(marks) |
|---|---|
| A | 90.0 |
| B | 72.0 |
| C | 55.0 |
| F | 40.5 |
INSERT adds new rows, UPDATE changes existing ones, and DELETE removes them. These are the core write operations and every real application uses all four: SELECT + INSERT + UPDATE + DELETE (often called CRUD).
| id | name | city | marks | grade |
|---|---|---|---|---|
| 1 | 'Rahul' | 'Delhi' | 72 | 'B' |
| 2 | 'Priya' | 'Mumbai' | 91 | 'A' |
| 3 | 'Arjun' | 'Delhi' | 38 | 'F' |
| 4 | 'Sneha' | 'Pune' | 85 | 'A' |
| 5 | 'Vikram' | 'Mumbai' | 55 | 'C' |
| 6 | 'Anita' | 'Delhi' | 94 | 'A' |
| 7 | 'Rohan' | 'Pune' | 43 | 'F' |
| id | name | city | marks | grade |
|---|---|---|---|---|
| 1 | Rahul | Delhi | 72 | B |
| 2 | Priya | Mumbai | 91 | A |
| 3 | Arjun | Delhi | 65 | C |
| 4 | Sneha | Pune | 85 | A |
| 5 | Vikram | Mumbai | 55 | C |
| 6 | Anita | Delhi | 94 | A |
| 8 | Karan | Bangalore | 78 | B |