-
Notifications
You must be signed in to change notification settings - Fork 0
/
variable_and_input_output.java
60 lines (44 loc) · 1.42 KB
/
variable_and_input_output.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.util.*;
class variables_and_input_output{
public static void main(String[] args) {
// output
// print function do not give \n after line white println function automatically gives \n
System.out.print("Hello World");
System.out.println("Hii world"); // \n is escape character called new line character
// Variables in java
/* java is a typed language so we need to declare the data type of variable initially.
There are 8 primitive data types and 5 non primitive data types.
primitive data types :-
1.byte
2.short
3.char
4.boolean
5.int
6.long
7.float
8.double
non-primitive data types:-
1. string
2.array
3.class
4.object
5.interface
*/
int a = 10;
int b = 20;
int c = a + b ;
System.out.println(c);
// input
Scanner scanner = new Scanner(System.in);
String s = scanner.next();
/*
for input we use scanner object from scanner class of java utils which takes input from user.
next delimits at space
nextLine function takes whole line
nextInt function for int input
nextFloat for float input
we have more such functions too.
*/
System.out.println(s);
}
}