Question

In: Computer Science

int a = 3; int b = -2; if((a>0)&&(b>0)){ if (a>b) { System.out.println("A"); } else {...

 int a = 3;
int b = -2;
if((a>0)&&(b>0)){
    if (a>b) {
        System.out.println("A");
    } else {
        System.out.println("B");
    }
} else if ((b<0)||(a<0)) {
    System.out.println("C");
} else {
    System.out.println("D");
}

Solutions

Expert Solution

If the above program is executed in java then value of variable "a" is 3 and value of variable "b" is -2

By using braching statement(if .. else statement) a> 0 and b > 0 , here logical and operator is used if the bothe condition is true then it will execute if part otherwise it will execute else part .

In First nested if part it check a>b it print A

else it print B

In second else part (b<0) || (a<0) it print "C " and actually this condition is true , because here logical or operator is used , here if one condition is true it will execute i, e value of b = -2 and it true because it check b< 0 and value of a is 3 it check a<0 it is false , hence according to logical or if one codition is true operation will perform .

Otherwie in last else part it will print "D"

Code :

public class First

{

     public static void main(String []args)

     {

            int a = 3;

            int b = -2;

            if((a>0)&&(b>0))

            {

                if (a>b)

                {

                    System.out.println("A");

                } else

                {

                    System.out.println("B");

                }

            }   

            else if ((b<0)||(a<0))

            {

                System.out.println("C");

            }

            else

            {

                System.out.println("D");

            }

}

}

Output:

C

Code (SS)

Output(SS):


Related Solutions

Find the output for the following statements. System.out.println(3%2+1+(3/2)); char ch = 69; System.out.println(ch); int x =...
Find the output for the following statements. System.out.println(3%2+1+(3/2)); char ch = 69; System.out.println(ch); int x = 30; int y = 4; double z = x/y; System.out.println(z);
In Java: int[] A = new int[2]; A[0] = 0; A[1] = 2; f(A[0],A[A[0]]); void f(int...
In Java: int[] A = new int[2]; A[0] = 0; A[1] = 2; f(A[0],A[A[0]]); void f(int x, int y) { x = 1; y = 3; } For each of the following parameter-passing methods, saw what the final values in the array A would be, after the call to f. (There may be more than one correct answer.) a. By value. b. By reference. c. By value-result.
what is the output? int main ( ) { int a = 3, b= 2, c=...
what is the output? int main ( ) { int a = 3, b= 2, c= 1, d, e, f, g; d = a&b;    e = a | c; f = a >> 1, g = a << 1; cout << “d= “ << d << “ e = “ << e << “ f = “ << f << “g = “ << g << endl; }
// 1. System.out.println("1."); int max = 5; for (int n = 1; n <= max; n++)...
// 1. System.out.println("1."); int max = 5; for (int n = 1; n <= max; n++) { System.out.println(n); } System.out.println(); // 2. System.out.println("2."); int total = 25; for (int number = 1; number <= (total / 2); number++) { total = total - number; System.out.println(total + " " + number); } System.out.println(); // 3. System.out.println("3."); for (int i = 1; i <= 2; i++) { for (int j = 1; j <= 3; j++) { for (int k = 1;...
Raw data ID X Y A 0 0 B 0 2 C 3 4 D 3...
Raw data ID X Y A 0 0 B 0 2 C 3 4 D 3 4 E 6 6 F 6 8 Standard scores ID STDX STDY A -1.22 -1.55 B -1.22 -0.78 C 0 0 D 0 0 E 1.22 0.78 F 1.22 1.55 1. What is the sum of squares regression? (correct answer is 36, please show work) 2. What can you conclude with ANOVA? (correct answer is Reject the null, p<0.01; type I error is possible,...
static int product(int x,int y){ if(x==0||y==0){//checking if x or y is 0 return 0;//if x or...
static int product(int x,int y){ if(x==0||y==0){//checking if x or y is 0 return 0;//if x or y is 0, then the return value and x*y will be zero. }else if(y<0&&x<0){ x=-x;//Changing the sign of x y=-y;//Changing the sign of y }else if(x>=1){ return (y+product(x-1,y)); } return (x+product(x,y-1)); } find the space complexity and the time complexity of the above algorithm.
Show the output of the following code segment. int count=0;                         for (int i=2; i <=...
Show the output of the following code segment. int count=0;                         for (int i=2; i <= 4; i++ ) {                                     StdOut.println(i);                                     for (int j=1; j <3; j++) {                                                 count++;                                                 StdOut.println(i +" " + j +" "+ count);                                     }                         } count i j I print 0 2 1 3 1 1 1 2 3 2 2 3 3 3 3 4 3 Show the output of the function call statements shown.             double x =...
int f2 (int n) j = 0; while (j <n) {for (int i = 0; i...
int f2 (int n) j = 0; while (j <n) {for (int i = 0; i <n; ++ i) {cout << "j =" + j; j = j + 5; }}
for square matrices A and B show that [A,B]=0 then [A^2,B]=0
for square matrices A and B show that [A,B]=0 then [A^2,B]=0
Assume that the following Ada like program compile successfully. int k = 0; A[3] = {0,...
Assume that the following Ada like program compile successfully. int k = 0; A[3] = {0, 1, 2}; void f(int p) {      cout<< A[k];      p*=3;      cout<< A[k];      p*=3;      cout<< A[k]; } int main () {      f(A[k++]);        // postfix      cout << A[1] << A[2] << endl; {    What is printed on the screen assuming? Pass by value Pass by reference Pass by value-result (assume lvalue is computed at call time) Pass by value-result...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT