Created
September 3, 2020 13:14
-
-
Save mrnirva/50936d99174f6ff8158754a268a25694 to your computer and use it in GitHub Desktop.
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
package tipdonusumu; | |
public class TipDonusumu { | |
public static void main(String[] args) { | |
// Küçük Tipten Büyük Tipe Döküm (Implicit Casting) | |
/* | |
Değer Kaybı Olmaz | |
Ondalık Kaybı Olmaz | |
Tip uyumluluğu sağlanır | |
Ekstra bir şeye gerek kalmadan atama operatörüyle yapılır | |
*/ | |
int intSayi = 50; | |
long lonSayi = intSayi; | |
byte byteSayi = 101; | |
double doubleSayi = byteSayi; | |
// Büyük Tipten Küçük Tipe Döküm (Explicit Casting) | |
/* | |
Değer Kaybı Olabilir | |
Ondalık Kaybı Olabilir | |
Tip Uyumluluğu sağlanmayabilir | |
Ekstra dönüşüm operatörü kullanılır | |
Dönüştürülecek değerin yanına parantez içine yeni tipi yazılır | |
*/ | |
int intTipi = 100; | |
byte byteTipi = (byte) intTipi; | |
// Burada önce byte dönüşüm sağlanır sonra atanır | |
double sayi1 = 4500000.7895f; | |
float sayi2 = (float) sayi1; | |
long sayi3 = (long) sayi1; | |
int sayi4 = (int) sayi1; | |
short sayi5 = (short) sayi1; | |
byte sayi6 = (byte) sayi1; | |
// Burada önce ilgili tiplere dönüşüm sağlanır sonra atanır | |
System.out.println("Sayi 1: "+sayi1); | |
System.out.println("Sayi 2: "+sayi2); | |
System.out.println("Sayi 3: "+sayi3); | |
System.out.println("Sayi 4: "+sayi4); | |
System.out.println("Sayi 5: "+sayi5); | |
System.out.println("Sayi 6: "+sayi6); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment