# Difference in the code on changing logical operators

• June 20th, 2009, 03:20 AM
lotus
Difference in the code on changing logical operators
Code :

```import java.util.Scanner;   class TicketPriceWithDiscount { public static void main(String args[]) { Scanner myScanner = new Scanner(System.in); int age; double price = 0.00; char reply;   System.out.print("How old are you? "); age = myScanner.nextInt();   System.out.print("Do you have a coupon? (Y/N)"); reply = myScanner.findInLine(".").charAt(0);   if(age >= 12 && age < 65){ price = 9.25; } if(age < 12 || age >= 65){ price = 5.25; } if(reply == 'Y' || reply =='y'){ price -= 2.00; } if(reply !='Y' && reply !='y' && reply !='N' && reply != 'n' ){ System.out.println("Huh"); } }   }```

for the above code i am wondering if i were to change the 1st IF condition
Code :

`if(age >= 12 && age < 65)`
into
Code :

`if(age >= 12 || age < 65)`
would there be a difference?? right now i am having problems differentiating && and ||. just started out programming here
• June 20th, 2009, 03:25 AM
Freaky Chris
Re: Question
&& requires both statements to be true before the if statement will execute, whereas
|| requires only 1 statement to be true before the if statement will execute.

Example

Code :

```public class lotus { public static void main(String[] args){ int a = 5, b = 3; if(a == 5 && b == 3) System.out.println("Look they both are true"); if(a == 5 && b == 7) System.out.println("Look only one is true, but using and so not printed"); if(a == 5 || b == 3) System.out.println("Look they both are true, so or will print"); if(a == 5 || b == 9) System.out.println("Look only one is true, by or means it will still print me"); if(a == 9 || b == 9) System.out.println("Neither are ture so im not printed"); } }```
• June 20th, 2009, 03:29 AM
lotus
Re: Question
ok i got it thanks
• June 20th, 2009, 03:30 AM
Freaky Chris
Re: Question
No problem, if thats everything could you please mark this as solved.

Chris