Java Tutorial 7 --- "Data Type of Expressions & Increment/Decrement Operators"
package com.company;
public class Tut7 {
public static void main(String[] args) {
// Data Type of Expressions & Increment/Decrement Operators
/*
b+s = int | b = byte
s+i = int | s = short
l+f = float | i = integer
i+f = float | l = long
c+i = int | f = float
c+s = int | d = double
l+d = double | c = character
f+d = double |
*/
// int i = 45 + 5;
// System.out.println(i);
// float f = 6.5f + 2;
// System.out.println(f);
// Increment & Decrement Operators
int i = 50;
System.out.println(i++); //First use i then increment
System.out.println(i);
System.out.println(++i); // First increment i then use
System.out.println(i);
//Quick Quiz: What Will be the value of the following expression (x):
//int y =7 ; int x = ++y*8
int y = 7;
int x = ++y*8;
System.out.println(x);
// For characters in JAVA
char ch = 'a';
System.out.println(++ch);
}
}
Comments
Post a Comment