Skip to content

Commit 7b790e9

Browse files
committed
revisit
1 parent 1d22907 commit 7b790e9

5 files changed

Lines changed: 34 additions & 27 deletions

File tree

‎java basic/4 arithmetic operations.txt‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,13 @@ System.out.println(-10 * (3 + 4) / 2)
3434
hint: If same priority operator comes then solve it from moving left to right
3535

3636
Q:
37+
a=b+++c;
38+
=> a = b+c and then b is incremented
39+
(but incremented value wont be used in this line, post increment)
40+
token created by lex are a, =, b, ++, +, c
41+
42+
Q
43+
a=b+++++c;
44+
Error
45+
tokens generated are a, =, b, ++, ++, +, c
46+
which is actually an error as there is no operand after second unary operand

‎java basic/src/basic/PlayGround.java‎

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,9 @@
55

66
public class PlayGround {
77
public static void main(String[] args) {
8-
byte b = 1;
9-
short s = 1;
10-
int n = 1;
11-
long l = 1;
12-
13-
m1(b); // byte
14-
m1(1); // int
15-
}
16-
17-
// static void m1(byte n) {
18-
// System.out.println("byte");
19-
// }
20-
static void m1(short n) {
21-
System.out.println("short");
22-
}
23-
static void m1(int n) {
24-
System.out.println("int");
25-
}
26-
static void m1(long n) {
27-
System.out.println("long");
8+
System.out.println( "System.console().readLine()" );
289
}
29-
static void m1(float n) {
30-
System.out.println("float");
10+
static {
11+
System.out.println( "System.console().readLine() static");
3112
}
3213
}

‎java basic/src/basic/ReadFourWords.java‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,24 @@ static void getInput(Scanner sc){
1717
}
1818

1919
public static void main(String[] args) {
20-
// put your code here
2120
Scanner sc = new Scanner(System.in);
2221
getInput(sc);
2322

2423
String[] wordsAll = inString.split("\n| ");
2524
for(int i=0; i<4; i++){
2625
System.out.println(wordsAll[i]);
2726
}
27+
sc.close();
2828
}
29+
30+
/* Or a simpler way,
31+
32+
public static void main(String[] args) {
33+
Scanner sc = new Scanner(System.in);
34+
for (int i = 0; i < 4; i++) {
35+
System.out.println(sc.next());
36+
}
37+
}*/
2938
}
3039

3140
/*

‎java basic/src/basic/RelationalOperators.java‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,8 @@ static void Q2() {
3535

3636

3737
/*
38-
Java provides six relational operators to compare numbers:
39-
4038
== (equal to)
4139
!= (not equal to)
4240
> (greater than)
43-
>= (greater than or equal to)
4441
< (less than)
45-
<= (less than or equal to)
4642
* */
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package basic;
2+
3+
public class StaticBlock {
4+
public static void main(String[] args) {
5+
System.out.println("System.console().readLine()");
6+
}
7+
8+
static {
9+
System.out.println("System.console().readLine() static");
10+
}
11+
}

0 commit comments

Comments
 (0)