2 variables in 1 "if" (new to java)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • brodyvon
    New Member
    • Sep 2010
    • 2

    #1

    2 variables in 1 "if" (new to java)

    so the program wants me to output the a word based on what the punctuation the user used to end the sentence.
    This is what i have so far, i know its really bad...
    Code:
    public class punctuation
    {
        public static void main(String[] args)
        {
            int sentence, length, even=%2, odd=%1;
    		char question=?, exclamation=!, other=.;
           
            System.out.println("Enter a sentence.");
            sentence = SavitchIn.readLineInt(); 
    		int length = sentence.length()
    		
    		if ( length == even , question)
    			System.out.println("YES");
    		else (sentence%1 == odd, question)
    			System.out.println("NO");
    		if (exclamation)
    			System.out.println("WOW");
    		if (other)
    			System.out.println("You always say" + sentence);
    		
            System.out.println("Press enter key to end program.");
            String junk;
            junk = SavitchIn.readLine();
        } 
    }
    Last edited by Nepomuk; Sep 8 '10, 10:22 AM. Reason: Please use [CODE] tags
  • Dheeraj Joshi
    Recognized Expert Top Contributor
    • Jul 2009
    • 1129

    #2
    Above code do not make any sense it is not a valid java code.

    Code:
    even=%2
    % is not allowed when you declare and initialize the variables.
    You can do find modulo of an declared variable.
    Code:
    int even=10;
    even = even%2;
    Code:
    char question=?;
    char variables must be enclosed within the single quotes.
    Code:
    char question='?';
    Code:
    if ( length == even , question)
    You can not compare the integer and character values like above.

    And what is SavitchIn? Are you using any custom API's?
    Code:
    SavitchIn.readLineInt();
    Is this a wrapper for System class API's?

    I suggest you read the JAVA syntax and programing basics to fine tune the program. So that it would at least compile.

    Regards
    Dheeraj Joshi

    Comment

    • brodyvon
      New Member
      • Sep 2010
      • 2

      #3
      Thanks for the help really appreciate it.

      Comment

      Working...