logo codesdope
Level 1
1.
Write a Java program to print an int, a double and a char on screen.
Answer
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.
Answer
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.
Answer
class Ans{
  public static void main(String[] args){
    System.out.println(8.2*6);
  }
}
									

4.
Print the ASCII value of the character 'h'.
Answer
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.
Answer
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.
Answer
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.
Answer
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.
Answer
class Ans{
  public static void main(String[] args){
    System.out.println(3.9*3.9);
  }
}
									
Doubt? Ask question
Close

Welcome.please sign up.

Close

Welcome.please login.