Knowee
Questions
Features
Study Tools

What will be the output of the below code? public static void main(String args[]) { int rollNo = 101; float newRollNo = rollNo; System.out.println(newRollNo); }

Question

What will be the output of the below code? public static void main(String args[]) { int rollNo = 101; float newRollNo = rollNo; System.out.println(newRollNo); }

🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the code will be 101.0.

Here's the step by step explanation:

  1. The main method is the entry point of the program.

  2. An integer variable rollNo is declared and initialized with the value 101.

  3. A float variable newRollNo is declared and it's initialized with the value of rollNo. Since rollNo is an integer, it's automatically converted to a float. This is called type casting.

  4. The System.out.println(newRollNo); statement prints the value of newRollNo to the console. Since newRollNo is a float, it's printed with a decimal point. So, 101 becomes 101.0.

This problem has been solved

Similar Questions

e correct answerWhat is the output of the following Java program?class Main { public static void main(String args[]) { final int i; i = 20; i = 30; System.out.println(i); }}

What is the output of the following code snippet?ArrayList<Integer> numbers = new ArrayList<>();numbers.add(1);numbers.add(2);numbers.add(3);System.out.println(numbers.get(2));

What will be the output of the following Java program?class java   {    public static void main(String args[])    {      int var1 = 3;       int var2 = 8;      if ((var2 = 2) == var1)        System.out.print(var2);      else         System.out.print(++var2);    }   }Options3421

What will be the output of the following code ?public static void print(int n){ if(n < 0){ return; } if(n == 0){ System.out.println(n); return; } print(n--); System.out.print(n+" ");}public static void main(String[] args) { int num = 3; print(num);

Select the correct answerWhat will be the output of the following Java program?class Output   {     public static void main(String args[])     {      double ct1 = 3.0;        double ct2 = 2.0;      double ct3 = Math.pow( ct1, ct2 );      System.out.print(ct3);    }  }Options3.02.09.08.0

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.