Boolean help

I need to design a programme which determines whether you are a taurus or not.
public class taurus1
public static void main (String args [])
boolean taurus;
int month,day;
month=4;
day=6;
if((month == 4) && (day > 20)) taurus = true;
if((month == 5) && (day < 22)) taurus = true;
System.out.println("You are a Taurus");
else{
System.out.println("You are not a Taurus");
1. I cant seem to get it to compile. What have i done as i get the error message "else without if"
2. i have seen other programmes that start by declaring boolean in this case boolean taurus=false; what is the meaning of this?

ZenitD wrote:
2. i have seen other programmes that start by declaring boolean in this case boolean taurus=false; what is the meaning of this?You can do that if the default value is false, and it only gets set to true if certain code paths are followed. However, I prefer to generally leave local variables uninitialized until some action in my code explicitly sets them. That way, if I miss a case in an if/else, for example, the compiler will complain.
boolean x = false;
if (y == 1) {
  x = true;
else if (z ==2 ) {
  x = false;
return x;What if I wanted x = true for anything other than y==1 or z==2? It will be false in that case, but I won't see it until there's unexpected behavior at runtime. That's more difficult to track down. If I had just done boolean x then the compiler would have complained about x not being set, and I would have known I have to go back an look at my cases. The WRONG thing to do in that situation is to just add the = false to the declaration to make the compiler happy. That just turns an easy-to-fix compile-time error into a hard-to-find runtime error.

Similar Messages

  • Boolean Help Please

    I am sure I should know this, goes back to my freakin beginngin C++ class, but I can't figure it out. I have a boolean search that is working on the server (I have a System.out to ensure that) but I cannot get it to report back to the calling method in the client properly. Each time it just says "successful." Can anyone help me figure this out? Could be that my brain is no longer functioning at 227am.
    Server Code:
    public boolean search(Registration aPerson)
    throws java.rmi.RemoteException, EntryNotFoundException {
    try{
    String mySSN = aPerson.getSSN();
    String myCID = aPerson.getCourseID();
    stmt = con.createStatement();
    String query = "";
    query = "SELECT SSN, COURSEID " +
    "FROM ENROLLMENT " +
    "WHERE SSN = '" + mySSN + "' AND " +
    "COURSEID = '" + myCID + "'";
    ResultSet rs = stmt.executeQuery(query);
    System.out.println("Reset Set executed");
    if(rs.next())
    System.out.println("Search Found.");
    else
    System.out.println("Search unsuccessful.");
    } //end of try
    /* catch block omitted */
    return(true);
    } //end of search Method
    Client side method:
    public static boolean search(RegSystem r)
    Registration aPerson = new Registration();
    boolean result;
    aPerson.setSSN(aPerson.readSSN());
    aPerson.setCourseID(aPerson.readCourseID());
    try{            //aPerson found
    result = r.search(aPerson);
    if(result == true)
    System.out.println("Search successful for person: " + aPerson);
    else
    System.out.println("Search Failed for person: " + aPerson);
    /* catch block omitted */
    return(true);
    } //end of search method
    Everything compiles and runs correctly, and outputs correctly on the server side, just not on the client.
    Thanks,
    Kimberly

    You are returning "true" from the server method whether the search is successful or not! Return true if sucessful and false if unsucessful.
    HTH,
    --Das                                                                                                                                                                                                                                                                                                           

  • How to setup Tiering with SCOM 2012 class libraries?

    Hi All,
    I've two SCOM servers installed in two different machines and SCOM will have some alerts. I want to connect the two so that one acts as top tier and other one as lower tier. The top tier will show all the alerts from the lower tier in
    the connected alerts. From there I'm passing the alerts to external system for processing. I want to establish the tiering programmatically using the SCOM 2012 API. I know of method
    TieringManagement.AddTier Method (String, ManagementGroupConnectionSettings, SecureData, Boolean)
    Help me how can I achieve this by using the above method.
    Thanks in advance.
    viRa

    To configure method TieringManagement.AddTier Method, you can refer to below links
    http://msdn.microsoft.com/en-us/library/hh332072.aspx
    http://msdn.microsoft.com/en-us/library/hh350608.aspx
    Please remember, if you see a post that helped you please click "Vote As Helpful" and if it answered your question, please click "Mark As Answer".

  • Help required in boolean pallette

    I will acquire one pulsed signal through DAQ card in labview. Now what exactly I want is that whenever the pulse is High(+5v) it should give me True(Boolean Value) and when pulse is low(0v) it should give me False(Boolean Value). 
    How this could be done in LabVIEW?
    Please Help.
    Solved!
    Go to Solution.

    Are you using a Digital Input or an Analog Input on your DAQ?
    If the Digital Input, you should just have a boolean comming out.
    If the Analog Input, then use the Greater? function with your read value to compare it to some threshold.  2.5V is a typical threshold for a TTL signal (5V).
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • [Help plz]Can't set a boolean attribute to true or false

    Hello,
    I'm new in NWDS development. I need to develop a download functionality
    I used a FileDownload UIElement for that and I created a node context (ExcelExport) with 3 attributes :
    - ExcelFile
    - ExcelIcon
    - And ExcelEnabled (Boolean type)
    My problem is that everytime I try to set the attribute ExcelEnabled to true or false, it return me a java.lang.NullPointerException
    I'm binding this attribute with "Enabled" property of the UIElement.
    Have anyone got this error before? Thanks a lot for your help.
    Kind regards,
    Safae.

    Hello Safae,
    Have you tried to put true/false value for the enabled property? I mean without using a context attribute?
    Also try to create the attribute out of the node.
    Regards,
    ImaneA.

  • Boolean Datatype declaration in PowerBuilder...Please HELP

    Hi,
    I have Oracle Stored procedure with last parameter as boolean, When I am calling this stored procedure in
    PowerBuilder 6.5 in the DECLARE I am getting compilation error and it is not working...
    I heard that there is some round about way to solve this problem...
    Any one knows the solution...please help me out...

    I don't know about PowerBuilder but we had a similar problem with Java not understanding Oracle's BOOLEAN implementation. I'm afraid we solved this by substituting a VARCHAR2 parameter with values of 'TRUE' and 'FALSE'. Not very elegant I'm afraid, but if your stored procedure is in a package you can at least overload it.
    cheers, APC

  • Boolean Array-- Help Plz Urgent

    Can i create and initialize an array of booleans like this ?
    Boolean[51] Position = true;
    Thanks... Plz help

    This works:Boolean[] bools = {
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true)
    };... and, fortunately, so does this:Boolean[] bools = new Boolean[51];
    java.util.Arrays.fill(bools, new Boolean(true));I hope you find this of some help.

  • Help with booleans and Buttons

    Hi,
    while ( repeat ) {
        tempValue = compMove.getRandomNumber();
        if ( nought.getUsedSquare(tempValue) ) {
            repeat = true;
        else if ( crosses.getUsedSquare(tempValue) ) {
            repeat = true;
        else {
            playButton[tempValue].setLabel("O");
            playButton[tempValue].setEnabled(false);
            nought.setSquareUsed(tempValue);
            repeat = false;
    }getUsedSquare(tempValue) - Should return true if button is used
    This code gets a random number in the range 0 to 8, and then uses this random number to check if a button has already been clicked and had its label changed using the getSquareUsed method. If the button has not been clicked then the label should be changed. Basically it is a Tic-Tac-Toe game.
    The problem is that sometimes the code will change the label on a button that has already been clicked.
    Why is this?
    Thanks for any help you can give.

    Alright:
    if ( event.getSource() == playButton[0] ) {
        playButton[0].setLabel("X");
        crosses.setSquareUsed(0);
        if ( crosses.checkForWin() )
            System.out.println("Crosses Win!");
        while ( repeat ) {
            tempValue = compMove.getRandomNumber();
            if ( nought.getUsedSquare(tempValue) )
                repeat = true;
            else if ( crosses.getUsedSquare(tempValue) )
                repeat = true;
            else {
                playButton[tempValue].setLabel("O");
                playButton[tempValue].setEnabled(false);
                nought.setSquareUsed(tempValue);
                repeat = false;
        repeat = true;
        if ( nought.checkForWin() )
            System.out.println("Noughts Win!");
        playButton[0].setEnabled(false);
    }That is the code i have for when the human player clicks on a button, the computer will make a random move, nothing intelligent about it (bit like me).
    I changed my coding for the getSquareUsed method to:
    public boolean getUsedSquare( int a ) {
       return squareUsed[a];
    }I know that the button is set as being used in the setSquareUsed method, but still the computer player will overwrite an already used square.
    Any ideas from this, or should i start again with something different?

  • If you are good at Booleans please help!

    I modified one of the Labview examples for continuously acquiring data inside a simple state machine. I want a single "Run" button and a single "Exit" button (which will stop the VI completely and ultimately bring them back to the main menu). The user should be able to push the "Run" button multiple times until they are done.
    I can't for the life of me get the booleans right!Boolean Logic just is NOT my thing. I'm getting better at it every day, slowly though.
    I'm attaching the VI below, your help is much appreciated. Let me know where I went wrong THANK YOUUU!!!!
    I have LabVIEW 6.1.
    Lauren
    Attachments:
    SingleScan-BooleanHelp.vi ‏163 KB

    In 6.1 you can use the event structure to do what you want it to do. if this doesn't help send me your global VI's and be more specific as to what exactly you want help with.
    Here is a modified VI.
    Joe
    Joe.
    "NOTHING IS EVER EASY"
    Attachments:
    SingleScan-BooleanHelp[1].vi ‏120 KB

  • I am stumped! Can't open library module-  failure message and can't start Ligthroom 5.7 anymore: "[String "unarchived table s"]:6 : attempt to compare nil with boolean. - Nothing is working anymore! Who can help me?

    My system:
    Windows 7
    Lightroom 5.7
    I allready tried to load an older catalog backup, but that does not help.
    The failure message occurs during the starting process while trying to Open the library:
    "[String "unarchived table s"]:6 : attempt to compare nil with boolean.
    Nothing is working anymore! Who can help me?
    Thank you for your help!

    Ask on the Microsoft forums, as it's their software you're having problems with:
    http://answers.microsoft.com/en-us/mac

  • Boolean Search and Search Help

    Can someone please update the Search Help, because the help on boolean searches makes no explicit reference to upper-case, and the examples imply case insensitivity, as can be seen in the following:
    Can phrases such as AND, OR, NOT be used when searching?
    Yes. These phrases are called Boolean Expressions. You can search using Oracle and Databases. This will return pages that contain both words. When the search Oracle or Databases is used, this will return a page that contains either of the words. When the search Oracle not Databases is used, this will return pages that only contain the word Oracle.
    Thanks.

    I would try a GREP find/change searching for (_)([^_]+)(_) and replace with $2 Set the change formatting to italics (preferably as a character style).  This translates to look for a _, then anything that is not a _, followed by another _, and replace with only the stuff in between. You can also use (_)(.+?)(_) which would match the shortest srting in between two _ characters in the same way (except it won't cross a paragraph break), but it will run a bit slower.
    Credit for this should go to Peter Kahrel and his excellent GREP primer....

  • String to boolean. Help needed.

    Hello ppl. Im here concerning my method for deleting files. I've got a bit of a difficulty....
    The method returns a String, becuase if an exception occurs it will return it, however if no exception occurs it returns true, as a String tho:
    return "true";
    Is there anyway to parse a string to a boolean value inside the method? or the invoking method?
    Method:
    public String delFile(String file){
    String error = null;
    File f = null;
    if(file!=null){
    try {
    f = new File(file);
    f.delete();
    } catch(SecurityException se){
    error = se.getMessage();
    if(error!=null) return error;
    return "true";
    Help appreciated. Thanks.

    Can I implement the custom exception method in the
    same class as the delFile() method?I think you got me wrong. You could do it like this:
    (1) Define your special exception class, which should
    be defined in a seperate file ("MyFileException.java")
    package myFileHandlingPackage;
    import java.io.*;
    public class MyFileException extends Exception{
    public final static int FILE_NOT_FOUND = 0;
    public final static int FILE_NAME_NULL = 1;
    public final static int NO_DELETION_PERMISSION = 2;
    private final static String[] messages;
    static{
       messages[] = new String[3];
       messages[0] = "The specified file could be found";
       messages[1] = "The file name was not specified";
       messages[2] = "You have no permission to delete the file";
    private int errorCode = -1;
    private File errorFile;
    public MyFileException(){
       super();
    public MyFileException(String msg){
       super(msg);
    public MyFileException(int errorCode, File errFile, String msg){
       MyFileException(msg);
       this.errorCode = errorCode;
       this.errorFile = errFile;
    public String getNiceMessage(){
       String niceMsg = "";
       if(errorCode != -1 && errorCode < 3){
         niceMsg += messages[errorCode];
         niceMsg += " ";
         niceMsg += errFile.getName();
       return niceMsg;
    }(2) import this class in your JSP and in the file you defined your
    delFile() method.
    (3) now you can use a catch(MyFileException mfe){...} in your JSP
    Hope that helps
    Adrian

  • Please help me, boolean function

    Hello everyone, this is my first post in this forum. I have this function but I cant get it to work because I get this "missing return statement". Im desperate now, I cant figure how to fix it. Please help me.
    public static boolean es(String inst) {                              // Verificador de validez
              int ad=inst.indexOf("ADELANTE");
              int at=inst.indexOf("ATRAS");
              int iz=inst.indexOf("IZQUIERDA");
              int de=inst.indexOf("DERECHA");
              int bo=inst.indexOf("BORRAR");
              int ho=inst.indexOf("HOGAR");
              double numero;
              try {
                   if ((ad==0)&&(inst.charAt(8)==' ')) {
                        numero = Double.parseDouble(inst.substring(9));
                        if (numero>0)
                             return true;
                        else return false;
                   if ((at==0)&&(inst.charAt(5)==' ')) {
                        numero = Double.parseDouble(inst.substring(6));
                        if (numero>0)
                             return true;
                        else return false;
                   if ((iz==0)&&(inst.charAt(9)==' ')) {
                        numero = Double.parseDouble(inst.substring(10));
                        if ((numero>0)&&(numero<360))
                             return true;
                        else return false;
                   if ((de==0)&&(inst.charAt(7)==' ')) {
                        numero = Double.parseDouble(inst.substring(8));
                        if ((numero>0)&&(numero<360))
                             return true;
                        else return false;
                   if (bo==0) return true;
                   if (ho==0) return true;
                   else return false;
              catch (NumberFormatException ex) {
         }The objective of this function is to check if the user entered one of these words: "adelante", "atras", "izquierda" or "derecha" followed by a positive number. Thank you in advance for your help.

    you need to have a return statement at the very end of you method.
    here's a rewrite of what you provided...instead of a bunch of returns everywhere, i set a variable to return. i also put else if statements instead of if since you only want to see if one of the instances exist
    public static boolean es(String inst) {                              // Verificador de validez
              int ad=inst.indexOf("ADELANTE");
              int at=inst.indexOf("ATRAS");
              int iz=inst.indexOf("IZQUIERDA");
              int de=inst.indexOf("DERECHA");
              int bo=inst.indexOf("BORRAR");
              int ho=inst.indexOf("HOGAR");
              double numero;
              boolean answer = false;
              try {
                   if ((ad==0)&&(inst.charAt(8)==' ')) {
                        numero = Double.parseDouble(inst.substring(9));
                        if (numero>0)
                             answer = true;
                        else answer = false;
                   else if ((at==0)&&(inst.charAt(5)==' ')) {
                        numero = Double.parseDouble(inst.substring(6));
                        if (numero>0)
                             answer = true;
                        else answer = false;
                   else if ((iz==0)&&(inst.charAt(9)==' ')) {
                        numero = Double.parseDouble(inst.substring(10));
                        if ((numero>0)&&(numero<360))
                             answer = true;
                        else answer = false;
                   else if ((de==0)&&(inst.charAt(7)==' ')) {
                        numero = Double.parseDouble(inst.substring(8));
                        if ((numero>0)&&(numero<360))
                             answer = true;
                        else answer = false;
                   else if (bo==0) answer = true;
                   else if (ho==0) answer = true;
                   else answer = false;
              catch (NumberFormatException ex) {
    answer = false;
              return answer;
    Message was edited by:
    muzic

  • Boolean search in apple mail help needed

    i tried this boolean search in apple mail - in an account that had these people, but it didn't work....
    Q: what am i doing wrong?
    to:[email protected] or to:[email protected]

    Maybe this page can help you construct complex searches in Mail:
    *http://www.hawaii.edu/askus/879*
    I noticed this line in the page:
    +Note: When searching Mac Mail does not use some frequently used wildcard searches. Use of the asterisk * or the syntax teresa@somewhere returns no matches.+

  • Boolean matrix - Please Help

    Would anyone be able to help me out with code to create a boolean (1/0) for a GUI? Iam looking to use a matrix of up to 10 rows and columbs that would resize depending on an entered value. It would then be possible to use the mouse to click on each element within the matrix to make it a 1 or a 0. I would appretiate any help.

    yay !!!!
    import java.awt.*;
    import java.awt.event.*;
    import java.util.BitSet;
    import javax.swing.*;
    import javax.swing.event.MouseInputAdapter;
    * @author  Ian Schneider
    public class BooleanMatrix extends JPanel {
        BitSet bits;
        int w = 10;
        int h = 10;
        /** Creates a new instance of BooleanMatrix */
        public BooleanMatrix() {
            resizeMatrix(w,h);
            MouseUpdater updater = new MouseUpdater();
            addMouseListener(updater);
            addMouseMotionListener(updater);
        public boolean isSet(int x,int y) {
            return bits.get(idx(x,y));
        public void toggle(int x,int y) {
            bits.flip(idx(x,y));
        private int idx(int x,int y) {
            return x + y * w;
        public void resizeMatrix(int w,int h) {
            bits = new BitSet(w * h);
            this.w = w;
            this.h = h;
        public Dimension getPreferredSize() {
            return new Dimension(w * 10,h* 10);
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            for (int i = 0, ii = w; i < ii; i++) {
                for (int j = 0, jj = h; j < jj; j++) {
                    if (isSet(i,j))
                        g.setColor(Color.green);
                    else
                        g.setColor(Color.red);
                    g.fillOval(i * 10 + 2,  j * 10 + 2, 6,6);
        class MouseUpdater extends MouseInputAdapter {
            public void mouseClicked(MouseEvent me) {
                int x = me.getX() / 10;
                int y = me.getY() / 10;
                toggle(x,y);
                repaint();
            public void mouseDragged(MouseEvent me) {
                mouseClicked(me);
        public static final void main(String[] args) throws Exception {
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
            f.getContentPane().add(new BooleanMatrix());
            f.pack();
            f.setLocationRelativeTo(null);
            f.show();
    }The rest of the exercises are left to the student :)

Maybe you are looking for

  • How to avoid messages going automatically to the archive folder in Apple Mail?

    Dear list members, I've been using Apple Mail (version 7.3 (1878.6)) on my MacBook Pro 13" (9,2) (MacOS 10.9.4) for years to integrate my GMail, university, and other e-mail accounts in the imap mode. Since some weeks, Mail is behaving odd: some mess

  • Video Lags Behind Audio in Preview Pane, Timeline and Rendered Video

    Hello, I'm having an issue with a six minute video that I grabbed from the media browser in Premeire and am attempting to use in my timline.  The first few mins of the 6 minute video is fine, but as the video progresses in the preview pane the video

  • How to use Dynamic Internal table

    Hello, I have a requirement where I need to pick a field from final internal table and display that field as ALV columns and I have to pick another field in the same INternal table to display it as a corresponding value for each header DYNAMICALLY. l

  • Transparency Layer Drops Out of PDF Export

    I have an InDesign CS3 layout. I have placed grayscale tiff at 100% as the background, and I have a small image in the foreground covering about a 1/4 of the background image, screened back to 40%. When I export to PDF at "Press Quality", the small s

  • Why cant i put videos on my nano

    why cant we? is there a way? like a hack?