Question

In: Computer Science

Given the Java code: double x =15; int n=15; Find the return value: a. x/2 b....

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)

Solutions

Expert Solution

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.


Related Solutions

What is the output of the following piece of Java code? int id = 4; double...
What is the output of the following piece of Java code? int id = 4; double grossPay = 81.475; String jobType = "Intern"; System.out.printf("Id: %d, Type: %s, Amount:%.2f", id,grossPay,jobType); Select one: Error Id: 4, Type: Intern, Amount: $81.475 Id: 4, Type: $81.475, Amount: Intern Id: 4, Type: $81.48, Amount:Intern Id: 4, Type: Intern, Amount: $81.48
Given the following Java code: class C { public int foo(C p) { return 1; }...
Given the following Java code: class C { public int foo(C p) { return 1; } } class D extends C { public int foo(C p) { return 2; } public int foo(D p) { return 3; } } C p = new C(); C q = new D(); D r = new D(); int i = p.foo(r); int j = q.foo(q); int k = q.foo(r); (Remember that in Java every object is accessed through a pointer and that methods...
Write a full MIPS assembly code for: Function Compare(int A[][], int B[][], int M, int N,...
Write a full MIPS assembly code for: Function Compare(int A[][], int B[][], int M, int N, int i, int j, int k, int l). This function compares the elements of the array A placed between (i,j) and (k,l) with the corresponding elements of the array B placed between the same indexes. The function returns the number of elements of both matrices that coincide in the same position (c,d). That is, it is necessary to check each element A[c,d] with the...
Given the function N(x)=x^(1.2) + x -ln(x) - 2 Find the roots of N(x) in the...
Given the function N(x)=x^(1.2) + x -ln(x) - 2 Find the roots of N(x) in the domain 0.1 ? x ? 2.5 using the MATLAB fzero function. Plot N(x) using fplot to find the estimates of the roots. Use a for-loop that calls the fzero function and prints the roots to 3 decimal places. Define N(x) using an anonymous function definition, and pass your function using your anonymous function
Given the root C++ code: void sort() {    const int N = 10;    int...
Given the root C++ code: void sort() {    const int N = 10;    int x[N];    for(int i = 0; i < N; i++)    {        x[i] = 1 + gRandom-> Rndm() * 10;        cout<<x[i]<<" "; }    cout<<endl;    int t;       for(int i = 0; i < N; i++)    {    for(int j = i+1; j < N; j++)    {        if(x[j] < x[i])        {   ...
Given the method static int test(int x, int y, int z){ return(x=y+z); } Which of the...
Given the method static int test(int x, int y, int z){ return(x=y+z); } Which of the follwing is true: public static void main(String[] args) { A System.out.println(test ( 7, 14, 23)) ; B System.out.println(test ( test ( 7,9, 14) , 23 ); C System.out.println( test ( 14, 23 ) ; D System.out.println(test(1,2,4), 14, 23)) ;
acos() Prototype double acos(double x); To find arc cosine of type int, float or long double,...
acos() Prototype double acos(double x); To find arc cosine of type int, float or long double, you can explicitly convert the type to double using cast operator. int x = 0; double result; result = acos(double(x)); int x = 0; double result; result = acos(double(x)); acos() Parameter The acos() function takes a single argument in the range of [-1, +1]. It's because the value of cosine is in the range of 1 and -1. Parameter Description double value Required. A...
Translate following C# code into MIPS assembly language int recursive(int x) { return (x >= 0xFF)...
Translate following C# code into MIPS assembly language int recursive(int x) { return (x >= 0xFF) ? (recursive(x - 3) + recursive(x - 2)) : ((x >= 0xF) ? recursive(x - 1) + 1 : 1);
COMPLETE JAVA CODE public class Point2 { private double x; private double y;    /** *...
COMPLETE JAVA CODE public class Point2 { private double x; private double y;    /** * Create a point with coordinates <code>(0, 0)</code>. */ public Point2() { complete JAVA code this.set(0.0, 0.0); COMPLETE CODE }    /** * Create a point with coordinates <code>(newX, newY)</code>. * * @param newX the x-coordinate of the point * @param newY the y-coordinate of the point */ public Point2(double newX, double newY) { complete Java code this.set(newX, newY); }    /** * Create a...
What is the value of n after this code runs? 1 Point int n = 0;...
What is the value of n after this code runs? 1 Point int n = 0; int j = 7; if ((j!=0) && (n < 25)) { n = 1; if (j > 4) { n = 2; } else { n = 3; } } else { n = 4; if (j%2 >= 2) { n = 5; } else { n = 6; } }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT