Question:

Java programming, need help with simple boolean decode =]

by  |  earlier

0 LIKES UnLike

hey, i need help with a simple boolean decode. i need a program that, if character c that the user enters isnt the letter z, it comes out false, however if the user enters the character z, it comes out true. ive written it, compiled and it has no errors, however it doesnt work?

any help plzzzz =] thanks heaps

public class Decode {

public static boolean decode (char c) {

if (c == 'z') {

return true;

} else {return false;}

}

}

also, if possible, i need this style coding =]

 Tags:

   Report

2 ANSWERS


  1. public class Main {

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

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

            char c;

            System.out.println("Enter a letter: ");

            c = (char)br.read();

            System.out.println("Result is " + decode(c));

         }

        

        public static boolean decode (char c) {

    if (c == 'z') return true;

    return false;

    }

    }

    I hope that helps.


  2. I don't see anything wrong with the function definition offhand. Can you post the invoking code as well to see if that might be the problem?

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.