vendredi 19 août 2016

Which comes first? The char or the String?

Most of the examples I find in my search for the answer are embedded in complex code. I'm just trying to have a question program know to accept either upper or lower case responses to a two-answer (binary?) question and then to use either answer to proceed to a singular result. I tried an if/else approach before I found character class methods in my book, but it only helps half way with it's examples.

here's the code:

 import java.util.Scanner;
public class MarriageQuiz
{
public static void main(String[] args)
{   
  char isMarried = 'M';
  char isSingle = 'S';
  String marStat;

  System.out.print("Please enter your Marital Status (M or S) >> ");
  marStat = input.nextLine();

     if(marStat.isUppercase(isMarried | isSingle))
     {
        marStat = input.nextLine();
     }
     else if((marStat.isLowercase(isMarried | isSingle)))
     {
        marStat = marStat.toUpperCase(isMarried | isSingle);
     }
     System.out.print("You are " + marStat);
}
} 

Aucun commentaire:

Enregistrer un commentaire