1 / 12

Declaration of Data Types

Declaration of Data Types. Character Declaration. public class CharExample { public static void main(String [] args ) { char ch1 = 'a'; char ch2 = 65; System.out.println ("Value of char variable ch1 is :"+ ch1); System.out.println ("Value of char variable ch2 is :"+ ch2); }

newton
Download Presentation

Declaration of Data Types

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Declaration of Data Types

  2. Character Declaration public class CharExample { public static void main(String [] args) { char ch1 = 'a'; char ch2 = 65; System.out.println("Value of char variable ch1 is :"+ ch1); System.out.println("Value of char variable ch2 is :"+ ch2); } }

  3. Character Declaration public class CharExample2 { public static void main(String [] args) { char c = 'A'; char tab = '\t'; char nul = ' '; char aleph = '\u05D0'; char backslash = '\\'; char singleQuote ='\''; char doubleQuote = '\"'; System.out.println(c); System.out.println(tab); System.out.println(singleQuote); } }

  4. Byte Declaration public class ByteExample { public static void main(String [] args) { byte b1 = 100; byte b2 = 20; System.out.println("The value of b1 is:"+ b1); System.out.println("The value of b2 is:"+ b2); } }

  5. Boolean Declaration public class BooleanExample { public static void main(String [] args) { boolean b1 = true; boolean b2 = false; System.out.println("The value of b1 is:"+b1); System.out.println("The values of b2 is:"+b2); } }

  6. Double Declaration public class DoubleExample { public static void main(String [] args) { double a = 23.45; double b = 15.235; System.out.println("The double value in a is:"+ a); System.out.println("The double value in b is:"+b); } }

  7. Float Declaration public class FloatExample { public static void main (String [] args) { float f = 10.4f; System.out.println("The float value of f is:"+ f); } }

  8. Integer Declaration public class IntExample { public static void main (String [] args) { int a = 5; int b = 10; System.out.println("The integer in a is:"+ a); System.out.println("The integer in b is:"+ b); } }

  9. Short Declaration public class ShortExample { public static void main(String []args) { short s1 = 50; short s2 = 42; System.out.println("The value of s1 is :"+ s1); System.out.println("The value of s2 is :"+ s2); } }

  10. String Declaration public class StringExample { public static void main(String [] args) { String name = "Leah Marie"; String lname = "Niluag"; System.out.println("My firstname is "+name); System.out.println("My surname is "+lname); } }

  11. Literal Test public class LiteralTest { public static void main(String[] args) { String name = "Tan Ah Teck"; // String is double-quoted char gender = 'm'; // char is single-quoted booleanisMarried = true; // true or false byte numChildren = 8; // Range of byte is [-127, 128] short yearOfBirth = 1945; // Range of short is [-32767, 32768]. Beyond byte intsalary = 88000; // Beyond the ranges of byte and short long netAsset = 8234567890L; // Need suffix 'L' for long. Beyond int double weight = 88.88; // With fractional part float gpa = 3.88f; // Need suffix 'f' for float

  12. Literal Test // println() can be used to print value of any type System.out.println("Name is " + name); System.out.println("Gender is " + gender); System.out.println("Is married is " + isMarried); System.out.println("Number of children is " + numChildren); System.out.println("Year of birth is " + yearOfBirth); System.out.println("Salary is " + salary); System.out.println("Net Asset is " + netAsset); System.out.println("Weight is " + weight); System.out.println("GPA is " + gpa); } }

More Related