vendredi 23 janvier 2015

Using result of a scan.nextLine with an if-else statement -- Java

I'm trying to make a BAC (blood alcohol content) calculator that takes inputs from the user and lets them know if they qualify to win... a grand DUI prize! I'm trying to use the Scanner to determine if the person is a male or female and then use an if-then statement down the line based on what the user input...but I don't really know how. It should be a very simple fix, but here's what I have and kinda what I want to do with the if-then statement commented out.



import java.util.*;

public class Proj2_Mazzone
{
public static void main (String[] args)
{

Scanner scan = new Scanner(System.in);

String gender;
int D, W, H, age;


...



System.out.print("Enter M if you're a male, or F if you're a female: ");
gender = scan.nextLine();

/*if(gender = M)
{
System.out.println("You're a man!");
}
else if(gender = F)
{
System.out.println("You're a woman!");
}
*/

Aucun commentaire:

Enregistrer un commentaire