Select language
Română
English
Français
Deutsch
Italiano
Español
Home
Languages ▾
CPP
C
CS
GO
JAVA
Python
Html
JS
CSS
PHP
Hard Lessons ▾
Hard Lesson 1
Hard Lesson 2
Hard Lesson 3
Hard Lesson 4
Hard Lesson 5
Hard Lesson 6
Hard Lesson 7
Hard Lesson 8
Hard Lesson 9
Hard Lesson 10
Hard Lesson 11
Hard Lesson 12
Compiler
Account
JAVA
Example
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Input: "); int n = sc.nextInt(); System.out.println("You entered: " + n); } } OUTPUT: Input: 5 You entered: 5
Variables
- int - EX: 100 - Size: 4 bytes - float - EX: 5.67f - Size: 4 bytes - double - EX: 5.678 - Size: 8 bytes - char - EX: 'A' - Size: 2 bytes - String - EX: "Hello" - Size: depends - boolean - EX: true/false - Size: 1 bit - long - EX: 1000000L - Size: 8 bytes - short - EX: 100 - Size: 2 bytes - byte - EX: 127 - Size: 1 byte
Input
import java.util.Scanner; Scanner sc = new Scanner(System.in); int number = sc.nextInt(); System.out.println("Number: " + number); char character = sc.next().charAt(0); System.out.println("Character: " + character);
Output
System.out.print("text"); // No newline System.out.println("text"); // With newline System.out.println(variable); System.out.println((char)65); // Outputs: A
Comments
// This is a single-line comment /* This is a multi-line comment */
Functions
public static int add(int a, int b) { return a + b; } // Usage: int result = add(5, 3); System.out.println(result); // void = no return value public static void greet(String name) { System.out.println("Hello " + name); }