If else statement

how can i make if else statement with 2 logical &&

Page 1 of 1

4 Replies - 3137 Views - Last Post: 14 December 2008 - 06:42 PM Rate Topic: -----

#1 iceangelfire17  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 28-November 08

If else statement

Posted 13 December 2008 - 11:45 PM

here is my code, how can i make the if else statement work, when i compile it, it results to '(' expected.

here is my code


import java.io.*; 

class LogIn{
  public static void main (String[] args) throws IOException {

	BufferedReader x = new BufferedReader
	  (new InputStreamReader(System.in));
	  
   BufferedReader y = new BufferedReader
	  (new InputStreamReader(System.in));
	
	  
	double UserID; 
	double User = 001;
	double Pin;
	double UserPin = 1234;
	String a = "User Number 1";
	double UserID2; 
	double User = 002;
	double Pin2;
	double UserPin = 2345;
	String b = "User Number 2";
   
	
	
	
	
	

	System.out.print ("Enter UserID  : ");
	UserID = Integer.parseInt( x.readLine());
	
	System.out.print ("Enter Pin  : ");
	Pin = Integer.parseInt( y.readLine());
	
	
	//operation
	
	if ((UserID == User) && (Pin == UserPin)) {
			System.out.println("Your Name is "+a);
		   System.out.println("Your Successfully LoggedIn");
	 } 
	if else ((UserID == User) && (Pin == UserPin)) {
			System.out.println("Your Name is "+B);
		   System.out.println("Your Successfully LoggedIn");
	 } 
	
	 
  
	 else

			{
			System.out.println("Log In Unsuccesfull");
		}
  
	
		
	 
   
		
		 }
	
	
}


Mod edit: Please :code:

Is This A Good Question/Topic? 0
  • +

Replies To: If else statement

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: If else statement

Posted 14 December 2008 - 03:33 AM

Please post your code using - :code:

Use
else if ((UserID == User) && (Pin == UserPin)) {
not
if else ((UserID == User) && (Pin == UserPin)) {

See The if-then and if-then-else Statements

This post has been edited by n8wxs: 14 December 2008 - 03:34 AM

Was This Post Helpful? 0
  • +
  • -

#3 iceangelfire17  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 28-November 08

Re: If else statement

Posted 14 December 2008 - 06:25 AM

help me find the error with this. the error says that variable UserID2 might not been initialized

here is my code


import java.io.*; 

class LogIn32{
  public static void main (String[] args) throws IOException {

	BufferedReader x = new BufferedReader
	  (new InputStreamReader(System.in));
	  
   BufferedReader y = new BufferedReader
	  (new InputStreamReader(System.in));
	
	  
	String UserID; 
	String User = "ASH";
	double Pin;
	double UserPin = 1234;
	String UserID2; 
	String User2 = "Blink";
	double Pin2;
	double UserPin2 = 2345;
	
	

	System.out.print ("Username  : ");
	UserID = ( x.readLine());
	
	System.out.print ("Enter Pin  : ");
	Pin = Integer.parseInt ( y.readLine());
	
	
	//operation
	
	if (UserID.equals(User) && (Pin == UserPin)) {
			System.out.println("Your Name is "+User);
		   System.out.println("Your Successfully LoggedIn");
	 } 
	else if ((UserID2 == User2) && (Pin2 == UserPin2)) {
			System.out.println("Your Name is "+User2);
		   System.out.println("Your Successfully LoggedIn");
	 } 
	 else

			{
			System.out.println("Log In Unsuccesfull");
		}
		
	}
		
}


*Please use the [ code] tags it make your code easier to read (and debug)
:code:

This post has been edited by pbl: 14 December 2008 - 05:45 PM

Was This Post Helpful? 0
  • +
  • -

#4 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: If else statement

Posted 14 December 2008 - 08:26 AM

else if ((UserID2 == User2) && (Pin2 == UserPin2)) {


you havent given UserID2 a value, how can you use it in an if statement and compare if you havent initialized it?
Was This Post Helpful? 0
  • +
  • -

#5 iceangelfire17  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 28-November 08

Re: If else statement

Posted 14 December 2008 - 06:42 PM

i got it,, thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1