7 Replies - 626 Views - Last Post: 29 February 2020 - 04:12 AM Rate Topic: -----

#1 supNub   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 25-December 19

(IF ) help please

Posted 28 February 2020 - 03:01 PM

Cant figure qout why every time i selct (Female) the IF statment will not work i cnat get the (Female )info

import java.util.Scanner;
public class Main 
{
    public static void main(String[] args) 
    {
        //options
        
        String option1 ="male";
        String option2 = "female";
        String superher = "superhero";
        String supervill = "supervillain";
           // int num1 = 0;
     System.out.print("Please select male or female : ");
         
            //check two strings 
        Scanner myScan = new Scanner(System.in);    //boolean isEqualString2 = option1.equals(option2);   
         String myScan2 = myScan.nextLine();
if (myScan2.contains("male") ){
       
             System.out.println("you selected  "+ option1  ); 
              
              System.out.println("are you a superhero or super villian? ");
              String myscan4 = myScan.nextLine();
              
        if  (myscan4.contains("superhero")){
                    System.out.println("you are a " +myscan4 );
                    System.out.println("do you like steak or sushi? ");
                    String myscan5 = myScan.nextLine();
        if  (myscan5.contains("steak"))
                    System.out.println("you like " +myscan5 + " YOU SHOULD GET A FLAT TOP" );
                
        if (myscan5.contains("sushi"))
                    System.out.println("you like " +myscan5 + " YOU SHOULD GET A POMPADOUR" );  
              }
        if (myscan4.contains("supervillain"))
                  System.out.println("you are a " +myscan4 + "YOU SHOULD GET A MOHAWK"); 
                   
                /*if(num1== 5){
                    System.out.print(".");
                } */  
          }
                
                
              /*  System.out.println("do you like steak or sushi? ");
                String myscan5 = myScan.nextLine();
              if (myscan5.contains("steak"))
                  System.out.println("you like " +myscan5 + " YOU SHOULD GET A FLAT TOP" );*/
                  
                  
else if (myScan2.contains("female") ){
             System.out.println("you selected  "+ option2  ); 
              
              System.out.println("are you a superhero or super villian? ");
              String myscan6 = myScan.nextLine();
              
         if (myscan6.contains("superhero")){
                    System.out.println("you are a " +myscan6 );
                    System.out.println("do you like anime or sitcom? ");
                    String myscan7 = myScan.nextLine();
         if (myscan7.contains("anime"))
                    System.out.println("you like " +myscan7 + " YOU SHOULD GET BANGS" );
                    String myscan5 = myScan.nextLine();
       if (myscan5.contains("sushi"))
                    System.out.println("you like " +myscan5 + " YOU SHOULD GET A POMPADOUR" );  
              }
                /*else if (myscan4.contains("supervillain"))
                  System.out.println("you are a " +myscan4 + "YOU SHOULD GET A MOHAWK"); */
                   
                /*if(num1== 5){
                    System.out.print(".");
                } */  
          }
                  
              
              
              
             
             
        
	    String myScan3= myScan.nextLine();
	    
	    if (myScan3.contains("superhero")){
	        System.out.print("you have chosen filter out Message with profanitySuperhero");
	    }
	    
	    else if (myScan3.contains("super villian")){
	        System.out.print("the profane word is: Super Villian" );
	    }
         
         
   } }


This post has been edited by no2pencil: 28 February 2020 - 04:40 PM
Reason for edit:: Added Code Tags


Is This A Good Question/Topic? 0
  • +

Replies To: (IF ) help please

#2 g00se   User is online

  • D.I.C Lover
  • member icon

Reputation: 3664
  • View blog
  • Posts: 16,838
  • Joined: 20-September 08

Re: (IF ) help please

Posted 28 February 2020 - 05:00 PM

Quote

if (myScan2.contains("male") ){


Well "female" contains "male" doesn't it?
Was This Post Helpful? 1
  • +
  • -

#3 supNub   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 25-December 19

Re: (IF ) help please

Posted 28 February 2020 - 07:54 PM

not really certain what you mean
Was This Post Helpful? 0
  • +
  • -

#4 supNub   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 25-December 19

Re: (IF ) help please

Posted 28 February 2020 - 08:34 PM

the way its supposed to work if i enters (female ) its supposed to have ask

SUPERHERO/SUPERVILLAN



SUPERHERO/SUPERVILLAN****selecting suppervillian for eather male or female branch will end the questions with "you should get a Mohawk"

***but selecting superhero for female branch should ask
ANIME /SITCOM
Was This Post Helpful? 0
  • +
  • -

#5 jon.kiparsky   User is online

  • Beginner
  • member icon


Reputation: 11836
  • View blog
  • Posts: 20,067
  • Joined: 19-March 11

Re: (IF ) help please

Posted 28 February 2020 - 10:56 PM

View PostsupNub, on 28 February 2020 - 09:54 PM, said:

not really certain what you mean



Any string that contains the character sequence "female" also contains the character sequence "male" because the latter is a subsequence of the former. Just like you can't spell "team" without "tea", and you can't spell "character sequence" without "ter seq".
Was This Post Helpful? 2
  • +
  • -

#6 supNub   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 25-December 19

Re: (IF ) help please

Posted 28 February 2020 - 11:10 PM

ooooooooooooooo i see that now THANKS SOOOOOO MUCH
what should i use instead of .contains() so it will see the difference between female and male
Was This Post Helpful? 0
  • +
  • -

#7 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 994
  • View blog
  • Posts: 3,901
  • Joined: 13-June 14

Re: (IF ) help please

Posted 28 February 2020 - 11:51 PM

Why don't you just check that the strings are equal? You've got a relevant comment on line 16.
Was This Post Helpful? 0
  • +
  • -

#8 g00se   User is online

  • D.I.C Lover
  • member icon

Reputation: 3664
  • View blog
  • Posts: 16,838
  • Joined: 20-September 08

Re: (IF ) help please

Posted 29 February 2020 - 04:12 AM

Yes, though equalsIgnoreCase would be better
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1