Hey everyone,

Just curious why my little program doesn't go through the if-statement I specified in it.

public static void main (String args[]){
		
		
		Scanner sc = new Scanner(System.in);
		
		System.out.println("Enter a value for girls:");
		int GIRLS = sc.nextInt();
		
		System.out.println("Enter a value for boys:");
		int BOYS = sc.nextInt();
		
		
		
		if (BOYS == 12 && GIRLS == 15){
			System.out.print("Here we go, you're passing the test.");
				
		}    <<<<<<<<<<<<<<<<<< Not checking the condition.  After I enter the values, it terminates.

Recommended Answers

All 4 Replies

Add a print statement just before the if statement to print out the values of BOYS and GIRLS. Perhaps the printout will show you the problem.

Copy the console when you execute the program and paste it here that shows the problem.
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'

Paste here.

Also add an else clause to the if that prints out a message.

Try typing 15 12 on one line before pressing Enter. You're having a problem with Scanner.

Can you post the logic beind the if? Maybe you meant to use the >= instead of the ==

Ur code works fine. I think u might hv make mistake while giving the values. U r getting the values for GIRLS first and then BOYS but in the IF statement u write BOYS
first and then GIRLS.

commented: Don't give wrong advices if don't know the very basics! -3

getting the values for GIRLS first and then BOYS but in the IF statement u write BOYS first and then GIRLS.

The order the data is read is completely irrelevant to the order in the if test.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.