This is some handy inc or dec operators.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class IncrementOperator { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
int pen = 5; | |
int pencil = 1; | |
//Post increment | |
System.out.println(pen++); | |
System.out.println(pen); | |
//Pre increment | |
System.out.println(++pencil); | |
// add n to it | |
pencil +=10; | |
System.out.println(pencil); | |
// mul n to it | |
pencil *=10; | |
System.out.println(pencil); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 | |
2 | |
12 | |
120 |
No comments:
Post a Comment