Last active
July 30, 2016 16:35
-
-
Save dimMaryanto93/519ff848171cb9924338d28343cb1989 to your computer and use it in GitHub Desktop.
Java - Variable dan Scope
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.time.LocalDate; | |
import java.util.Date; | |
public class VariableDate{ | |
public static void main(String[] args) { | |
LocalDate localDate = LocalDate.now(); | |
System.out.println("java.time.LocalDate : "+localDate); | |
Date date = new Date(); | |
System.out.println("java.util.Date : "+date); | |
} | |
} |
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
public class VariableDouble{ | |
public static void main(String[] args) { | |
Double bilPositif = new Double(10); | |
Double bilNegatif = -5.4; | |
Double pertambahan = bilPositif + bilNegatif; | |
System.out.println("Bilangan Positif : "+ bilPositif); | |
System.out.println("Bilangan Negatif : "+ bilNegatif); | |
System.out.println("Perjumlahan antara bilPositif dan bilNegatif adalah "+ pertambahan); | |
} | |
} |
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
public class VariableFloat{ | |
public static void main(String[] args) { | |
float bilPositif = new Float(10); | |
float bilNegatif = -5.4F; | |
float pertambahan = bilPositif + bilNegatif; | |
System.out.println("Bilangan Positif : "+ bilPositif); | |
System.out.println("Bilangan Negatif : "+ bilNegatif); | |
System.out.println("Perjumlahan antara bilPositif dan bilNegatif adalah "+ pertambahan); | |
} | |
} |
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
public class GlobalVariabel{ | |
private static String nama = "Dimas Maryanto"; | |
public static void main(String[] args) { | |
System.out.println("ini dari main : "+ nama); | |
fungsiLain(); | |
} | |
public static void fungsiLain(){ | |
System.out.println("Ini dari fungsiLain : "+ nama); | |
} | |
} |
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
public class VariableInteger{ | |
public static void main(String[] args) { | |
Integer bilPositif = 10; | |
Integer bilNegatif = -5; | |
Integer pertambahan = bilPositif + bilNegatif; | |
System.out.println("Bilangan Positif : "+ bilPositif); | |
System.out.println("Bilangan Negatif : "+ bilNegatif); | |
System.out.println("Perjumlahan antara bilPositif dan bilNegatif adalah "+ pertambahan); | |
} | |
} |
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
public class LocalVariabel{ | |
public static void main(String[] args) { | |
String nama = "Dimas Maryanto"; | |
System.out.println(nama); | |
} | |
public void fungsiLain(){ | |
// System.out.println(nama); # variabel nama tidak dikenali | |
} | |
} |
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
public class ParamsVariabel{ | |
private static String nama = "Dimas"; | |
public static void main(String[] args) { | |
fungsiLain("Maryanto"); | |
} | |
public static void fungsiLain(String nama){ | |
System.out.println(ParamsVariabel.nama + " " + nama); | |
} | |
} |
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
public class VariableString{ | |
public static void main(String[] args){ | |
String fistName = "Dimas"; | |
String lastName = "Maryanto"; | |
System.out.println(nama + " "+ lastName); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment