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

COMPUTER SOFTWARE APPLICATION - CITS




                   // shortValue()
                   short shortResult = shortValue.shortValue();
                   System.out.println(“shortValue(): “ + shortResult);

                   // intValue()
                   int intResult = shortValue.intValue();
                   System.out.println(“intValue(): “ + intResult);


                   // longValue()
                   long longResult = shortValue.longValue();
                   System.out.println(“longValue(): “ + longResult);
                  // floatValue()
                   float floatResult = shortValue.floatValue();
                   System.out.println(“floatValue(): “ + floatResult);


                   // doubleValue()
                   double doubleResult = shortValue.doubleValue();
                   System.out.println(“doubleValue(): “ + doubleResult);
               }
           }


           Output:




















           3  Integer
              •  Represents a 32-bit signed integer.
              •  Methods include: intValue(), longValue(), floatValue(), doubleValue().

              Task_Integer:  Here’s an example program demonstrating the use of methods inherited from the Number
              class for the Integer class:
              public class IntegerMethodsExample {
                 public static void main(String[] args) {
                   // Example using Integer class
                  Integer intValue = 42;

                   // intValue()
                   int intResult = intValue.intValue();
                   System.out.println(“intValue(): “ + intResult);



                                                           56

                               CITS : IT & ITES - Computer Software Application - Exercise 90
   66   67   68   69   70   71   72   73   74   75   76