Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Java while-Loop with yes/no conditions using Char?

i can't stick the loop in my program..

need to use any Looping (While/Do/For) inserting if/else condition in the middle then continuing with yes or no if they want to retake it and No to quit. If you can't use CHAR, you can replace the yes=1 no=2. Would appreciate any help possible!

import java.io.*;

public class SECRET

{

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

{

BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

int birthdate;

int birthmonth;

System.out.println("Enter your birthdate");

System.out.println("1 to 31 only");

birthdate=Integer.parseInt(in.readLine());

System.out.println("Enter your birthmonth");

System.out.println("1 to 12 only");

birthmonth=Integer.parseInt(in.readLine());

if(birthdate>=21&&birthmonth==3)

{

System.out.println("You are an Aries");

}

else if(birthdate<=20&&birthmonth==4)

{

System.out.println("You are an Aries");

}

else if(birthdate>=21&&birthmonth==4)

{

System.out.println("You are a Taurus");

}

else if(birthdate<=20&&birthmonth==5)

{

System.out.println("You are a Taurus");

}

else if(birthdate>=21&&birthmonth==5)

{

System.out.println("You are a Gemini");

}

else if(birthdate<=20&&birthmonth==6)

{

System.out.println("You are a Gemini");

}

else if(birthdate>=21&&birthmonth==6)

{

System.out.println("You are a Cancer");

}

else if(birthdate<=20&&birthmonth==7)

{

System.out.println("You are a Cancer");

}

else if(birthdate>=21&&birthmonth==7)

{

System.out.println("You are a Leo");

}

else if(birthdate<=20&&birthmonth==8)

{

System.out.println("You are a Leo");

}

else if(birthdate>=21&&birthmonth==8)

{

System.out.println("You are a Virgo");

}

else if(birthdate<=20&&birthmonth==9)

{

System.out.println("You are a Virgo");

}

else if(birthdate>=21&&birthmonth==9)

{

System.out.println("You are a Libra");

}

else if(birthdate<=20&&birthmonth==10)

{

System.out.println("You are a Libra");

}

else if(birthdate>=21&&birthmonth==10)

{

System.out.println("You are a Scorpio");

}

else if(birthdate<=20&&birthmonth==11)

{

System.out.println("You are a Scorpio");

}

else if(birthdate>=21&&birthmonth==11)

{

System.out.println("You are a Scorpio");

}

else if(birthdate<=20&&birthmonth==12)

{

System.out.println("You are a Sagittarius");

}

else if(birthdate>=21&&birthmonth==12)

{

System.out.println("You are a Sagittarius");

}

else if(birthdate<=20&&birthmonth==1)

{

System.out.println("You are a Capricorn");

}

else if(birthdate>=21&&birthmonth==1)

{

System.out.println("You are a Capricorn");

}

else if(birthdate<=20&&birthmonth==2)

{

System.out.println("You are an Aquarius");

}

else if(birthdate>=21&&birthmonth==2)

{

System.out.println("You are an Aquarius");

}

else if(birthdate<=20&&birthmonth==3)

{

System.out.println("You are a Pisces");

}

else

{

System.out.println("Invalid Input");

}

String cont;

char ans;

System.out.println("Do you want to continue?");

System.out.println("If Yes, press Y. If No, press N");

cont=in.readLine();

}

}

If anyone wants to use this,go ahead.It works except for the looping. It asks the user for 2numbers(bdate&bmonth) and then gives the user their corresponding Western ZodiacSign (",

1 Answer

Relevance
  • 9 years ago
    Favorite Answer

    before

    System.out.println("Enter your birthdate");

    put:

    bool loopAgain = true;

    do {

    and after

    cont=in.readLine();

    put:

    if(cont.equalsIgnoreCase("N"))

    loopAgain = false;

    else

    loopAgain = true;

    } while (loopAgain == true);

Still have questions? Get your answers by asking now.