import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String line = sc.nextLine(); // input one line
String word = sc.next(); // input one word
int num = sc.nextInt(); // input an integer number
int dob = sc.nextDouble(); // input a double number
System.out.println("Hello " + line + ", age = " + num); // print and make new line
System.out.print("Hello " + word + ", weight = " + dob); // print without new line
System.out.printf("%.2f\n", value); // print double with 2 decimal places
}
}
Sum of 3 numbers (one line input):
import java.util.Scanner;
public class SumThree {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
System.out.println(a + b + c);
}
}
Java — If Structure
int x = 10;
if (x > 0) {
System.out.println("Positive");
} else if (x < 0) {
System.out.println("Negative");
} else {
System.out.println("Zero");
}
Java — Loops
for (int i = 1; i <= 5; i++)
System.out.println(i);
int j = 1;
while (j <= 5) {
System.out.println(j);
j++;
}
Java — Arrays
int[] nums = {10, 20, 30};
for (int n : nums)
System.out.println(n);
System.out.println(nums[1]); // 20
Java — Strings
String s = "Hello Java";
System.out.println(s.length());
System.out.println(s.toUpperCase());
System.out.println(s.substring(0, 5));
System.out.println(s.contains("Java"));
🐍 Python — Input / Output
Basic input/output:
text = input() # input string
num = int(input()) #input number
print(text) # print and make a new line
print(num, end=' ') # print and make a space
print(f"Hello {name}, age = {age}")
print(f"{num:.2f}") # print with 2 decimal places
Sum of 3 numbers (one line input):
a, b, c = map(int, input().split())
print(a + b + c)
Python — If Structure
x = 10
if x > 0:
print("Positive")
elif x < 0:
print("Negative")
else:
print("Zero")
Python — Loops
for i in range(1, 6):
print(i)
j = 1
while j <= 5:
print(j)
j += 1
Python — Lists (Arrays)
nums = [10, 20, 30]
# Input an array
nums = list(map(int, input().split()))
for n in nums:
print(n)
print(nums[1]) # 20
Python — Strings
s = "Hello Python"
print(len(s))
print(s.upper())
print(s[0:5])
print("Python" in s)
✨ JavaScript — Input / Output (Custom Template)
Sum of 3 numbers from one line:
// Starter function main
function main() {
// Read 3 numbers in one line
let a = Number(input());
let b = Number(input());
let c = Number(input());
println(a + b + c); // print and make a new line
print(a.toFixed(2)); // print with 2 decimal places
}
// --- Simplified input/output system ---
const fs = require("fs");
// Read all lines
let rawLines = fs.readFileSync(0, "utf8").split("\n").map(line => line.replace(/\r$/, ""));
let lineIndex = 0;
let tokenIndex = 0;
let currentTokens = [];
// Read next token
function input() {
while (tokenIndex >= currentTokens.length) {
if (lineIndex >= rawLines.length) return "";
currentTokens = rawLines[lineIndex++].trim().split(/\s+/);
tokenIndex = 0;
}
return currentTokens[tokenIndex++];
}
// Read rest of current line
function inputLine() {
if (lineIndex >= rawLines.length && tokenIndex >= currentTokens.length) return "";
if (tokenIndex < currentTokens.length) {
let rest = currentTokens.slice(tokenIndex).join(" ");
tokenIndex = currentTokens.length;
return rest;
}
if (lineIndex < rawLines.length) {
let line = rawLines[lineIndex++];
currentTokens = line.trim().split(/\s+/);
tokenIndex = currentTokens.length;
return line;
}
return "";
}
function print(val) {
process.stdout.write(String(val));
}
function println(val) {
console.log(val);
}
main();
JavaScript — If Structure
let x = 10;
if (x > 0) {
console.log("Positive");
} else if (x < 0) {
console.log("Negative");
} else {
console.log("Zero");
}
JavaScript — Loops
for (let i = 1; i <= 5; i++)
console.log(i);
let j = 1;
while (j <= 5) {
console.log(j);
j++;
}
JavaScript — Arrays
let nums = [10, 20, 30];
// Loop through array
for (let n of nums) {
console.log(n); // prints each element
}
// Access by index
console.log(nums[1]); // 20
JavaScript — Strings
let s = "Hello JavaScript";
console.log(s.length);
console.log(s.toUpperCase());
console.log(s.substring(0, 5));
console.log(s.includes("Java"));