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

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.
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.
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
var1 db “b, “ca”, 0 var2 db 3, 0, 0, 0 var3 times 2 dw 012h...
var1 db “b, “ca”, 0 var2 db 3, 0, 0, 0 var3 times 2 dw 012h mov eax, var3 mov ebx, var1 sub eax, 4 add ebx, [eax] mov dword [ebx], 42 Show work on each step. Show final memory starting at "var1" on a Little-Endian Machine.
Let ?1 and ?2 have the joint pdf f (?1, ?2)= 6?2     0<?2<?1<1 =0 else where...
Let ?1 and ?2 have the joint pdf f (?1, ?2)= 6?2     0<?2<?1<1 =0 else where A. Find conditional mean and conditional variance ?1given?2 . B. Theorem of total mean and total variance?1given?2 .(urgently needed)
exampleInput.txt 1 2 3 0 2 3 4 0 1 3 5 0 1 2 6...
exampleInput.txt 1 2 3 0 2 3 4 0 1 3 5 0 1 2 6 1 5 6 8 2 4 6 7 3 4 5 9 10 5 8 9 4 7 9 6 7 8 6 How can I detect when 'cin' starts reading from a new line. The amount of numbers in each row is unknown. I need them in type 'int' to use the data.
int value = 1; do { if (value % 2 == 0) cout << value <<...
int value = 1; do { if (value % 2 == 0) cout << value << " "; value = value + 1; } while (value % 7 != 0); cout << "\n" << value; What will be displayed?
Consider the matrix A given by [ 2 0 0 ] [ 0 2 3 ]...
Consider the matrix A given by [ 2 0 0 ] [ 0 2 3 ] [ 0 3 10 ] (20) Find all its eigenvalues and corresponding eigenvectors. Show your work. (+5) Write down the entire eigendecomposition (i.e. the matrices X, Lambda, and X inverse) explicitly.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT