Java Quiz 1 : Data Types, Variables and Arrays

    Welcome to your Java Quiz 1 : Data Types, Variables and Arrays

    1. What is the range of short data type in Java?
    2. What is the range of byte data type in Java?
    3. Which of the following are legal lines of Java code?
     1. int w = (int)888.8; 2. byte x = (byte)100L; 3. long y = (byte)100; 4. byte z = (byte)100L;
    4. An expression involving byte, int, and literal numbers is promoted to which of these?
    5. Which of these literals can be contained in float data type variable?
    6. Which data type value is returned by all transcendental math functions?
    7. What will be the output of the following Java code?
    1.  class average {
    2.  public static void main(String args[])
    3.  {
    4.  double num[] = {5.5, 10.1, 11, 12.8, 56.9, 2.5};
    5.  double result;
    6.  result = 0;
    7.  for (int i = 0; i < 6; ++i) 
    8.  result = result + num[i];
    9.  System.out.print(result/6);
    10.  
    11.  } 
    12.  }
    8. What will be the output of the following Java statement?
    1. class output {
    2.  public static void main(String args[]) 
    3.  {
    4.  double a, b,c;
    5.  a = 3.0/0;
    6.  b = 0/4.0;
    7.  c=0/0.0;
    8.  
    9.  System.out.println(a);
    10.  System.out.println(b);
    11.  System.out.println(c);
    12.  } 
    13.  }
    9. What will be the output of the following Java code?
    1.  class increment {
    2.  public static void main(String args[]) 
    3.  { 
    4.  int g = 3;
    5.  System.out.print(++g * 8);
    6.  } 
    7.  }
    10. What will be the output of the following Java code?
    1.  class area {
    2.  public static void main(String args[]) 
    3.  { 
    4.  double r, pi, a;
    5.  r = 9.8;
    6.  pi = 3.14;
    7.  a = pi * r * r;
    8.  System.out.println(a);
    9.  } 
    10.  }
    11. What is the numerical range of a char data type in Java?
    12. Which of these coding types is used for data type characters in Java?
    13. Which of these values can a boolean variable contain?
    14. Which of these occupy first 0 to 127 in Unicode character set used for characters in Java?
    15. Which one is a valid declaration of a boolean?
    16. What will be the output of the following Java program?
    1.  class array_output {
    2.  public static void main(String args[]) 
    3.  { 
    4.  char array_variable [] = new char[10];
    5.  for (int i = 0; i < 10; ++i) {
    6.  array_variable[i] = 'i';
    7.  System.out.print(array_variable[i] + "" );
    8.  i++;
    9.  }
    10.  } 
    11.  }
    17. What will be the output of the following Java program?
    1.  class mainclass {
    2.  public static void main(String args[]) 
    3.  {
    4.  char a = 'A';
    5.  a++;
    6.  System.out.print((int)a);
    7.  } 
    8.  }
    18. What will be the output of the following Java program?
    1.  class mainclass {
    2.  public static void main(String args[]) 
    3.  {
    4.  boolean var1 = true;
    5.  boolean var2 = false;
    6.  if (var1)
    7.  System.out.println(var1);
    8.  else
    9.  System.out.println(var2);
    10.  } 
    11.  }
    19. What will be the output of the following Java code?
    1.  class booloperators {
    2.  public static void main(String args[]) 
    3.  {
    4.  boolean var1 = true;
    5.  boolean var2 = false;
    6.  System.out.println((var1 & var2));
    7.  } 
    8.  }
    20. What will be the output of the following Java code?
    1.  class asciicodes {
    2.  public static void main(String args[]) 
    3.  {
    4.  char var1 = 'A';
    5.  char var2 = 'a';
    6.  System.out.println((int)var1 + " " + (int)var2);
    7.  } 
    8.  }