Tuesday, July 13, 2021

6. Write a program to assign a value of 100.235 to a double variable and then convert it to int.

 public class Main {

      public static void main(String[] args) {

          double a = 100.235;

          System.out.println((int)a);

     }

}


NOTE:

  • Didn't use Scanner as there is no input to ask from the user.
  • Used double as we needed to change double.
  • Used System.out.println((int)a); to change double to int.
  • Double and int are different because Double can contain decimal value but int can not.                       For example : double is 100.235 then int will be 100 as it cant contain decimal values.

No comments:

Post a Comment