Knowee
Questions
Features
Study Tools

the correct answerWhat will be the output of the following Java code?    class codetantra     {        public static void main(String args[])         {            double m = 295.30;            int  n = 330;            byte o = (byte) m;            byte p = (byte) n;            System.out.println(o + " "  + p);        }     }

Question

the correct answerWhat will be the output of the following Java code?    class codetantra     {        public static void main(String args[])         {            double m = 295.30;            int  n = 330;            byte o = (byte) m;            byte p = (byte) n;            System.out.println(o + " "  + p);        }     }

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

Solution

The output of the Java code will be 39 -26.

Here's the step by step explanation:

  1. The code declares a double variable 'm' and assigns it the value 295.30.
  2. It then declares an integer variable 'n' and assigns it the value 330.
  3. The code then declares a byte variable 'o' and assigns it the value of 'm' cast to a byte. The byte data type in Java is 8 bits and has a minimum value of -128 and a maximum value of 127. When you cast a value that's larger than this to a byte, it will wrap around. So, 295.30 becomes 39.
  4. Similarly, it declares another byte variable 'p' and assigns it the value of 'n' cast to a byte. The value 330 wraps around to -26.
  5. Finally, the code prints out the values of 'o' and 'p', which are 39 and -26 respectively.

This problem has been solved

Similar Questions

Select the correct answerPredict the output of the following program.class codetantra{  public static void main(String[] args)  {    Double object = new Double("2.4");    int p = object.intValue();    byte q = object.byteValue();    float r = object.floatValue();    double s = object.doubleValue();     System.out.println(p + q + r + s );   }}Options8.888.800000095367432

What will be the output of the following Java code? class codetantra  {    public static void main(String args[])     {      char a = 'A';      char b = 76;      b++;      a++;      System.out.println(a + " " + b);    }   }OptionsC NB MD OA M

Select the correct answerWhat will be the output of the following Java program, if we run as “java Codetantra 4 7 9”?  class Codetantra  {    public static void main(String [] args)     {      String [][] argument = new String[2][2];      int a;      argument[0] = args;      a = argument[0].length;      for (int b = 0; b < a; b++)         System.out.print(" " + argument[0][b]);            }  }Options4 04 44 0 94 7 9

Select the correct answerWhat will be the output of the following Java program?import java.lang.System;  class Output   {    public static void main(String args[])    {      byte a[] = { 65, 66, 67, 68, 69, 70 };      byte b[] = { 71, 72, 73, 74, 75, 76 };        System.arraycopy(a, 0, b, 3, a.length - 3);      System.out.print(new String(a) + " " + new String(b));    }  }OptionsOPQRST UVWXYZOPQRST OPQRSTOPQRST UVWOPQUVWOPQ UVWOPQ

Select the correct answerWhat is the output of the following program?public class Score{   public static void main(String[] args)   {     byte var = 2;     var = (byte) var * 1; //line 1     byte data = (byte) (var * 1); //line 2     System.out.println(var);        }}OptionsCompilation error due to line 2Compilation error due to line 10

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.