rect 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
rect 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); } }
Solution
The output of the Java code will be "39 74".
Here's the step-by-step explanation:
- The code declares a double variable 'm' and assigns it the value 295.30.
- It then declares an integer variable 'n' and assigns it the value 330.
- 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 has a maximum value of 127, so when 295.30 is cast to a byte, it wraps around to 39.
- Similarly, it declares a byte variable 'p' and assigns it the value of 'n' cast to a byte. When 330 is cast to a byte, it wraps around to 74.
- Finally, the code prints out the values of 'o' and 'p', which are 39 and 74 respectively.
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
e correct answerWhat will be the output of the following Java code? class Codetantra { final public int output(int x, int y) { return 1; } } class Program extends Codetantra { public int output(int x, int y) { return 2; } } public class result { public static void main(String args[]) { Program object = new Program(); System.out.print("y is " + y.output(0, 1)); } }
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
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.