Page 27 - CTS - CSA TP - Volume 2
P. 27

COMPUTER SOFTWARE APPLICATION - CITS





           If there are no syntax errors in your code, the Java compiler (javac) will create a file named PrintDataTypes.class
           in the same directory.
           Step 3: Running the Java Program

           1  Run the Java Program:













           In the Command Prompt, type the command java filename (java PrintDataTypes) and press Enter:
           This command executes the main method in the PrintDataTypes class. You should see the values of the variables
           printed in the console.
           Summary
           This Java program declares variables of different primitive data types and prints their values to the console.
           Following the steps outlined above will allow you to create and run the program successfully.


           TASK 2 :  Write a Java program to display all primitive data types
           All the steps are same as that of the above program (See the steps of Task 1)
           CODE:
           public class PrimitiveExample {
               public static void main(String[] args) {

                   // Declare variables of different primitive data types
                   byte myByte = 10;
                   short myShort = 1000;
                   int myInt = 100000;

                   long myLong = 1000000000L;
                   float myFloat = 3.14f;
                   double myDouble = 3.14159;
                   boolean myBoolean = true;
                   char myChar = ‘A’;

                   // Print the values of the variables
                   System.out.println(“byte: “ + myByte);
                   System.out.println(“short: “ + myShort);
                   System.out.println(“int: “ + myInt);
                   System.out.println(“long: “ + myLong);

                   System.out.println(“float: “ + myFloat);
                   System.out.println(“double: “ + myDouble);
                   System.out.println(“boolean: “ + myBoolean);





                                                           12
                                CITS : IT & ITES - Computer Software Application - Exercise 81
   22   23   24   25   26   27   28   29   30   31   32