Close
Close

Practice questions on Know data-types

Level 1

1.
Write a Java program to print an int, a double and a char on screen.
class Ans{
  public static void main(String[] args){
    int x = 10;
    double y = 10.23;
    char z = 'z';
    System.out.println("int : "+x+"\nfloat : "+y+"\nchar : "+z);
  }
}

2.
Write a program to print the area of a rectangle of sides 2 and 3 units respectively.
class Ans{
  public static void main(String[] args){
    int area = 2*3;
    System.out.println("Area of recatngle is : "+area);
  }
}

3.
Write a program to print the product of the numbers 8.2 and 6.
class Ans{
  public static void main(String[] args){
    System.out.println(8.2*6);
  }
}

4.
Print the ASCII value of the character 'h'.
class Ans{
  public static void main(String[] args){
    System.out.println((int)'h');
  }
}

5.
Write a program to assign a value of 100.235 to a double variable and then convert it to int.
class Ans{
  public static void main(String[] args){
    double x = 100.235;
    System.out.println((int)x);
  }
}

6.
Write a program to add 3 to the ASCII value of the character 'd' and print the equivalent character.
class Ans{
  public static void main(String[] args){
    int x = 3+'d';
    System.out.println((char)x);
  }
}

7.
Write a program to add an integer variable having value 5 and a double variable having value 6.2.
class Ans{
  public static void main(String[] args){
    int x = 5;
    double y = 6.2;
    System.out.println(x+y);
  }
}

8.
Write a program to find the square of the number 3.9.
class Ans{
  public static void main(String[] args){
    System.out.println(3.9*3.9);
  }
}

Level 2

Level 3

Ask Yours
Post Yours