Posts

34 IF THEN STATEMENT

  package com.cnc ; public class Main { public static void main ( String [] args) { boolean isAlien = false ; if ( isAlien == false ) { System . out .println( "It is not an alien!" ); System . out .println( "And I am sacred of aliens" ); } } } OUTCOME It is not an alien! And I am sacred of aliens

32 OPERATORS, OPERANDS AND EXPRESSIONS

    //OPERATORS int myVar = 15 + 2 ; +--->operator 15 & 12 are operands //EXPRESSION 15 + 12 is the expression which returns 27 package com.cnc ; public class Main { public static void main ( String [] args) { int result = 1 + 2 ; // 1 + 2 = 3 System . out .println( "1 + 2 = " +result); int previousResult = result; System . out .println( "previousRESULT = " + previousResult ); result = result - 1 ; // 3 - 1 = 2 System . out .println( "3 -1 = " +result); System . out .println( "previousRESULT = " + previousResult ); result = result* 10 ; // 2 * 10 = 20 System . out .println( "2 * 10 = " +result); result = result/ 5 ; // 20 / 5 = 4 System . out .println( "20 / 5 = " +result ); result = result % 3 ; // remainder of (4 % 3) = 1 System . out .println( "4 % 3 = " +result);           //ABBREVIA

3 PRIMITIVE TYPES RECAP AND STRING DATA TYPE

1 byte 2 short 3 int 4 long 5 float 6 double 7 char 8  boolean package com.cnc ; public class Main { public static void main ( String [] args) { //STRING---> A SEQ OF CHAR String myString = "This is a string" ; System . out .println( "myString is = " +myString); myString = myString + ", and this is more.." ; System . out .println( "myString is = to " + myString); myString = myString+ " \u00A9 2020" ; System . out .println( "myString is = to " +myString); String numberString = "255.66" ; numberString = numberString+ "49.55" ; System . out .println(numberString); String lastString = "10" ; int myInt = 50 ; lastString = lastString + myInt ; System . out .println(lastString); } } OUTCOMES myString is = This is a string myString is = to This is a string, and this is more.. myStrin

2 THE CHAR AND BOOLEAN PRIMITIVE DATA TYPES

  package com.cnc ; public class Main { public static void main ( String [] args) { 7 // CHARACTER char myChar = 'D' ; It is different from string, it can only store only one character it occupies 2 bytes of memory or 16 bits so it does not a byte and allows to store UNICODE characters char myUnicodeChar = ' \u0044 ' ; THIS IS THE UNICODE OF D System . out .println( myUnicodeChar ); 8 // BOOLEAN boolean myTrueBooleanVal = true ; boolean myFalseBoooleanVal = false ; //Find adult or not. boolean adult = true ; } }

2 FLOATING POINT AND PRECISION AND CHALLENGE

package com.cnc ; public class Main { public static void main ( String [] args) { //FLOAT float myMinFloatVal = Float . MIN_VALUE ; float myMaxFloatVal = Float . MAX_VALUE ; System . out .println( "FLOAT MINIMUM VALUE =" + myMinFloatVal ); System . out .println( "FLOAT MAXIMUM VALUE =" + myMaxFloatVal ); //DOUBLE System . out .println( "" ); double myMinDoubleVal = Double . MIN_VALUE ; double myMaxDoubleVal = Double . MAX_VALUE ; System . out .println( "double MINIMUM VALUE =" + myMinDoubleVal ); System . out .println( "" ); System . out .println( "double MAXIMUM VALUE =" + myMaxDoubleVal ); int i = 5 ; float f = ( float ) 5.77 ; float f1 = 5.77f ; double d = 5.7755d ; double d1 = 5.7755 ; int i2 = 5 ; float f2 =