In: Computer Science
Given the Java code: double x =15; int n=15;
Find the return value: a. x/2
b. n/2
c. n/2.0
d. (double)(n/2)
Please upvote if you are able to understand this and if there is any query do mention it in the comment section.
a. CODE:
public class MyClass {
public static void main(String args[]) {
double x = 15;
int n = 15;
System.out.println(x / 2);//printing the return value of x /
2
}
}
OUTPUT:
b. CODE:
public class MyClass {
public static void main(String args[]) {
double x = 15;
int n = 15;
System.out.println(n / 2);//printing the return value of n /
2
}
}
OUTPUT:
c. CODE:
public class MyClass {
public static void main(String args[]) {
double x = 15;
int n = 15;
System.out.println(n / 2.0);//printing the return value of n /
2.0
}
}
OUTPUT:
d. CODE:
public class MyClass {
public static void main(String args[]) {
double x = 15;
int n = 15;
System.out.println((double)(n / 2));//printing the return value of
(double)(n / 2.0)
}
}
OUTPUT:
If anything else was required in this or this was supposed to be done in any other way then please mention it in the comment section otherwise please upvote.