Computer Science, asked by anishdev255, 8 months ago

//a program to display the numbers after swapping
import java.util.
public class Swap
public static void main(String args[])
Scanner in = new Scanner(System.in);
int a,b,c=0;
System.out.println("Enter your number");
a=in.nextInt();
b=in.nextInt();
c-a,
a=b;b=c;
System.out.println("the value of a ="+a);
System.out.println("the value of b="+b);
}
}

Explain the logic of this Java program​.

Answers

Answered by rithvikala
1

Answer:

Logical AND’ Operator(&&): This operator returns true when both the conditions under consideration are satisfied or are true. If even one of the two yields false, the operator results false. For example, cond1 && cond2 returns true when both cond1 and cond2 are true (i.e. non-zero).

Syntax:

condition1 && condition2

Example:

a = 10, b = 20, c = 20

condition1: a < b

condition2: b == c

if(condition1 && condition2)

d = a+b+c

// Since both the conditions are true

d = 50.

filter_none

edit

play_arrow

brightness_4

// Java code to illustrate  

// logical AND operator  

 

import java.io.*;  

 

class Logical {  

   public static void main(String[] args)  

   {  

       // initializing variables  

       int a = 10, b = 20, c = 20, d = 0;  

 

       // Displaying a, b, c  

       System.out.println("Var1 = " + a);  

       System.out.println("Var2 = " + b);  

       System.out.println("Var3 = " + c);  

 

       // using logical AND to verify  

       // two constraints  

       if ((a < b) && (b == c)) {  

           d = a + b + c;  

           System.out.println("The sum is: " + d);  

       }  

       else

           System.out.println("False conditions");  

   }  

}  

Output:

Var1 = 10

Var2 = 20

Var3 = 20

The sum is: 50

'Logical OR' Operator(||): This operator returns true when one of the two conditions under consideration are satisfied or are true. If even one of the two yields true, the operator results true. To make the result false, both the constraints need to return false.

Syntax:

condition1 || condition2

Example:

a = 10, b = 20, c = 20

condition1: a < b

condition2: b > c

if(condition1 || condition2)

d = a+b+c

// Since one of the condition is true

d = 50.

filter_none

edit

play_arrow

brightness_4

// Java code to illustrate  

// logical OR operator  

 

import java.io.*;  

 

class Logical {  

   public static void main(String[] args)  

   {  

       // initializing variables  

       int a = 10, b = 1, c = 10, d = 30;  

 

       // Displaying a, b, c  

       System.out.println("Var1 = " + a);  

       System.out.println("Var2 = " + b);  

       System.out.println("Var3 = " + c);  

       System.out.println("Var4 = " + d);  

 

       // using logical OR to verify  

       // two constraints  

       if (a > b || c == d)  

           System.out.println("One or both"

                              + " the conditions are true");  

       else

           System.out.println("Both the"

                              + " conditions are false");  

   }  

}  

Output:

Var1 = 10

Var2 = 1

Var3 = 10

Var4 = 30

One or both the conditions are true

'Logical NOT' Operator(!): Unlike the previous two, this is a unary operator and returns true when the condition under consideration is not satisfied or is a false condition. Basically, if the condition is false, the operation returns true and when the condition is true, the operation returns false.

Syntax:

!(condition)

Example:

a = 10, b = 20

!(a<b) // returns false

!(a>b) // returns true

filter_none

edit

play_arrow

brightness_4

// Java code to illustrate  

// logical NOT operator  

import java.io.*;  

 

class Logical {  

   public static void main(String[] args)  

   {  

       // initializing variables  

       int a = 10, b = 1;  

 

       // Displaying a, b, c  

       System.out.println("Var1 = " + a);  

       System.out.println("Var2 = " + b);  

 

       // Using logical NOT operator  

       System.out.println("!(a < b) = " + !(a < b));  

       System.out.println("!(a > b) = " + !(a > b));  

   }  

}  

Output:

Var1 = 10

Var2 = 1

!(a < b) = true

!(a > b) = false

Please mark as brainliest!!!!    

Hope it will help you!!!!

Answered by yashchirdhani
0

Answer:

please brainliest my answer ✌✌

please thanks my answer ❤❤

and please votes ✡️

Attachments:
Similar questions