Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8892847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:06:32+00:00 2026-06-14T23:06:32+00:00

I have decided to try and learn a little in java tonight and i

  • 0

I have decided to try and learn a little in java tonight and i have just been trying some stuff with things i have learned.

My question is in an if statement how to i make two stings to be true. Here is what i have so far.

if ("male".equals(gender)) && ("brendan".equals(name))

The problem i am pretty sure is the && but i am not sure.

EDIT EDIT EDIT.

This fixed part of the problem.
if("male".equals(gender) && "Brendan".equals(name))
and so did this

if (("male".equals(gender)) && ("brendan".equals(name)))

Now i will post the whole thing i am having another issue now and you would probably need to see the whole thing.

import java.util.Scanner;

public class my_input_and_if_statements 
{
    public static void main (String args[])
{
    Scanner jonks = new Scanner(System.in);
    String name, gender, answer;
    System.out.println("What is your name?");
    name = jonks.next();
    System.out.print("Hello ");
    System.out.print( name);
    System.out.println(" are you male or female?");
    gender = jonks.next();

        if (("male".equals(gender)) && ("brendan".equals(name)))            
            {
            System.out.println("blah blah");
            }

        else
            {
            System.out.println(" Welcome to one of my first java applications. I hope you like it");
            }

        if (("female".equals(gender)) && ("nicole".equals(name))) 
            {
            System.out.println("blah blah 2");
            }
        else
            {
            System.out.println(" Welcome to one of my first java applications. I hope you like it");
            }

            }
}

sorry if this seems kind of pointless just trying to tie some stuff in together before i start trying to learn some more.

now when i go through it gives me two lines when it finishes or it gives me both.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:06:33+00:00Added an answer on June 14, 2026 at 11:06 pm

    I think the issues is your parentheses.

    An if statement has the form if(condition), where condition is some boolean expression. In this case you’re wanting the condition to be "male".equals(gender) && "Brendan".equals(name), so your complete statement should be something like the following:

    if("male".equals(gender) && "Brendan".equals(name)) {
        //Foo Blah blah
    }
    else {
        //Barr fuzz fuzz
    }
    

    For the second part of your question, you have two if statements, both of which print on both the if and the else branches, so you’re going to hit one or other of the println statements in the first if and one or other of the println statements of the second if. I think what you probably wanted to do was something like the following:

    if(gender.equals("male") && name.equals("Brendan")) {
        println("Brendan's Message");
    }
    else if(gender.equals("female") && name.equals("Nicole")) {
        println("Nicole's Message");
    }
    else {
        println("Anybody's Message");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have decided to add some validation to my combobox, what I'm trying to
I am still trying to learn Java and decided to take it 1 step
I'm just getting ramped up on a new application and have decided to try
I'm trying to learn gtkmm, and decided to try gtkmm 2.4 for the time
I decided to try to my hand at this, and have had a somewhat
I have a working WAMP environment (Apache Friends). I decided to try Subversion and
I've decided that I am going to try and learn backbone.js by making a
I'm new to Zend framework and have decided to try to build a simple
I'm starting a new project and have decided to try to incorporate DDD patterns
I'm still at the early stages of learning WPF and have decided to try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.