Void and boolean

public void boolean compute(int n)
{ if n>5
     {return true; }
     else
   {return false; }
  }Is this subroutine possibly correct?
Is there any possibility for a subroutine to have void and boolean at the same time (not to mention an if without parentesis)??
Thank you
--david                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

What do you mean "void and boolean at the same time"?
If it compiles, then it's guaranteed to return a boolean value (unless it throws an exception, or the VM shuts down or something). The compiler is quite anal about that.
A simpler way to write it would be public void boolean compute(int n) {
    return n > 5;
} But then, you don't exactly need a method for that, do you.
The if without parens will not compile.

Similar Messages

  • Difference between void and null?

    wht is da difference between void and null w.r.t java?

    corlettk wrote:
    Why do you care, unless you're implementing a java compiler or JVM?Wow, you sure do suck at helping out in a forum. Why even make this post? You're not helping the OP any, and you made yourself look like a tool.
    To the op:
    Null is java's version of a null value. Java's version is more strict then many other languages, and will not work in a boolean expression or anywhere code expects a real and not null value. It's simply null.
    Void is java's way of declaring no return type on a method. Methods that are void take no 'return' statement and if one is provided will cause a fatal error. The exception to this is using 'return' without a value, which returns control to the caller of the method.
    Observe:
    //this method returns an int
    public int return_int(){
        int value = 5;
        return value;
    //this method does not return an int
    public void return_nothing(){
        int another_value = 123;
        System.out.println("Here's the value: " + return_int());
    //this method does not return anything
    public void nothing_returned(){
        return_nothing();
        return;
        System.out.println("This line never gets printed; the method returned control already!");
    }

  • How can i pass the values to method public static void showBoard(boolean[][

    I need x and y to pass to the method
    public static void showBoard(boolean[][] board
    i am very confused as to why its boolean,i know its an array but does that mean values ar true or false only?Thanks
    import java.util.Random;
    import java.util.Scanner;
    public class Life1
         public static void main(String[] args)
              int x=0;
              int y=0;
              Scanner keyIn = new Scanner(System.in);
              System.out.println("Enter the first dimension of the board : ");
              x = keyIn.nextInt();
              System.out.println("Enter the second dimension of the board : );
              y = keyIn.nextInt();
              boolean[][] board = new boolean[x][y];
              fillBoard(board);
              showBoard(board);
              //Ask the user how many generations to show.
              board = newBoard(board);
              showBoard(board);
         //This method randomly populates rows 5-9 of the board
         //Rewrite this method to allow the user to populate the board by entering the
         //coordinates of the live cells.  If the user requests that cell 1, 1 be alive,
         //your program should make cell 0,0 alive.
         public static void fillBoard(boolean[][] board)
              int row, col, isAlive;
              Random picker = new Random();
              for(row = 4; row < 9; row++)
                   for(col = 4; col < 9; col++)
                        if (picker.nextInt(2) == 0)
                          board[row][col] = false;
                        else
                          board[row][col] = true;
         //This method displays the board
         public static void showBoard(boolean[][] board)
              int row, col;
              System.out.println();
              for(row=0; row < x; row++)
                   for(col=0; col<y; col++)
                        if (board[row][col])
                             System.out.print("X");
                        else
                             System.out.print(".");
                   System.out.println();
              System.out.println();
         //This method creates the next generation and returns the new population
         public static boolean[][] newBoard(boolean[][] board)
              int row;
              int col;
              int neighbors;
              boolean[][] newBoard = new boolean[board.length][board[0].length];
              makeDead(newBoard);
              for(row = 1; row < board.length-1; row++)
                   for(col = 1; col < board[row].length-1; col++)
                        neighbors = countNeighbors(row, col, board);
                        //make this work with one less if
                        if (neighbors < 2)
                             newBoard[row][col]=false;
                        else if (neighbors > 3)
                             newBoard[row][col] = false;
                        else if (neighbors == 2)
                             newBoard[row][col]= board[row][col];
                        else
                             newBoard[row][col] = true;
              return newBoard;
         //This method counts the number of neighbors surrounding a cell.
         //It is given the current cell coordinates and the board
         public static int countNeighbors(int thisRow, int thisCol, boolean[][] board)
              int count = 0;
              int row, col;
              for (row = thisRow - 1; row < thisRow + 2; row++)
                   for(col = thisCol - 1; col < thisCol + 2; col++)
                     if (board[row][col])
                          count++;
              if (board[thisRow][thisCol])
                   count--;
              return count;
         //This method makes each cell in a board "dead."
         public static void makeDead(boolean[][] board)
              int row, col;
              for(row = 0; row < board.length; row++)
                   for(col = 0; col < board[row].length; col++)
                        board[row][col] = false;
    }

    this is what im workin with mabey you can point me in the right directionimport java.util.Random;
    /* This class creates an application to simulate John Conway's Life game.
    * Output is sent to the System.out object.
    * The rules for the Life game are as follows...
    * Your final version of the program should explain the game and its use
    * to the user.
    public class Life
         public static void main(String[] args)
              //Allow the user to specify the board size
              boolean[][] board = new boolean[10][10];
              fillBoard(board);
              showBoard(board);
              //Ask the user how many generations to show.
              board = newBoard(board);
              showBoard(board);
         //This method randomly populates rows 5-9 of the board
         //Rewrite this method to allow the user to populate the board by entering the
         //coordinates of the live cells.  If the user requests that cell 1, 1 be alive,
         //your program should make cell 0,0 alive.
         public static void fillBoard(boolean[][] board)
              int row, col, isAlive;
              Random picker = new Random();
              for(row = 4; row < 9; row++)
                   for(col = 4; col < 9; col++)
                        if (picker.nextInt(2) == 0)
                          board[row][col] = false;
                        else
                          board[row][col] = true;
         //This method displays the board
         public static void showBoard(boolean[][] board)
              int row, col;
              System.out.println();
              for(row=0; row < 10; row++)
                   for(col=0; col<10; col++)
                        if (board[row][col])
                             System.out.print("X");
                        else
                             System.out.print(".");
                   System.out.println();
              System.out.println();
         //This method creates the next generation and returns the new population
         public static boolean[][] newBoard(boolean[][] board)
              int row;
              int col;
              int neighbors;
              boolean[][] newBoard = new boolean[board.length][board[0].length];
              makeDead(newBoard);
              for(row = 1; row < board.length-1; row++)
                   for(col = 1; col < board[row].length-1; col++)
                        neighbors = countNeighbors(row, col, board);
                        //make this work with one less if
                        if (neighbors < 2)
                             newBoard[row][col]=false;
                        else if (neighbors > 3)
                             newBoard[row][col] = false;
                        else if (neighbors == 2)
                             newBoard[row][col]= board[row][col];
                        else
                             newBoard[row][col] = true;
              return newBoard;
         //This method counts the number of neighbors surrounding a cell.
         //It is given the current cell coordinates and the board
         public static int countNeighbors(int thisRow, int thisCol, boolean[][] board)
              int count = 0;
              int row, col;
              for (row = thisRow - 1; row < thisRow + 2; row++)
                   for(col = thisCol - 1; col < thisCol + 2; col++)
                     if (board[row][col])
                          count++;
              if (board[thisRow][thisCol])
                   count--;
              return count;
         //This method makes each cell in a board "dead."
         public static void makeDead(boolean[][] board)
              int row, col;
              for(row = 0; row < board.length; row++)
                   for(col = 0; col < board[row].length; col++)
                        board[row][col] = false;
    }

  • How do i convert void to boolean?

    Hi all,
    My problem is:
    This is one kind of java puzzle.
    if(System.out.println("I can "))
    The above sentence make the error like as incompatible type.cannot convert "void" to "boolean".Now I try to typecast void to boolean. It is not working at anyway.Please any have exposure about void to Object conversion.Please guide me.

    Don't put all your faith in Schrodinger....
    I repeated the "Schrodinger Cat" experiment, and
    could determine whether the cat was alive or dead.
    It was a function of time. After 4 or 5 days,
    s, the outcome was deterministic.Schr�dinger's Cat is bad OO. The cat does know its
    state, and that info should remain encapsulated. If
    you need it, you can still reference the animal and
    query it.Wouldn't the cat's state be more like a variable that has only been declared but not initialized? :^)
    - Saish

  • Difference between false and Boolean.FALSE ?

    Hello,
    can you please tell the difference between false and Boolean.FALSE ?

    The trap behind autoboxing is that things work just fine when at least one side of the equation is a primitive. Things turn out unexpected when all of a sudden both sides of the equation happen to be an object:
    public class Test {
         public static void main(String[] args){
              boolean bp = false;
              Boolean bo = new Boolean(false);
              Boolean bo2 = new Boolean(false);
              System.out.println("Primitive VS Boolean.FALSE: " + (bp == Boolean.FALSE));
              System.out.println("Primitive VS new object: " + (bp == bo));
              System.out.println("New object VS Boolean.FALSE: " + (bo == Boolean.FALSE));
              System.out.println("new object vs new object 2: " + (bo == bo2));
    }Result:
    Primitive VS Boolean.FALSE: true
    Primitive VS new object: true
    New object VS Boolean.FALSE: false
    new object vs new object 2: falseTry explaining that in the context of this thread without ever referring to autoboxing specifically. Remember that people find these posts through Google, if you pass out information while hiding the gritty details, it gets confusing.

  • Void and Cancelled Checks

    Hello All,
    What is the difference between void and cancelled checks?
    Thanks,
    Deki

    A voided cheque is one where the cheque number is marked as void but the payment document still exists. For example if a cheque was torn and you want to assign the payment to a different cheque.
    A cancelled cheque is when you did not intend to make that payment so you void the cheque and reversed the payment.

  • [svn] 4136: Find loop variables initialized with "weak" types, e.g., NULL or VOID, and

    Revision: 4136
    Author: [email protected]
    Date: 2008-11-18 14:50:38 -0800 (Tue, 18 Nov 2008)
    Log Message:
    Find loop variables initialized with "weak" types, e.g., NULL or VOID, and
    use the variable type used within the loop to normalize the local's type.
    Modified Paths:
    flex/sdk/trunk/modules/asc/src/java/adobe/abc/GlobalOptimizer.java

    Remember that Arch Arm is a different distribution, but we try to bend the rules and provide limited support for them.  This may or may not be unique to Arch Arm, so you might try asking on their forums as well.

  • Difference between public void, private void and public string

    Hi everyone,
    My 1st question is how do you know when to use public void, private void and public string? I am mightily cofuse with this.
    2ndly, Can anybody explain to me on following code snippet:
    Traceback B0;//the starting point  of Traceback
    // Traceback objects
    abstract class Traceback {
      int i, j;                     // absolute coordinates
    // Traceback2 objects for simple gap costs
    class Traceback2 extends Traceback {
      public Traceback2(int i, int j)
      { this.i = i; this.j = j; }
    }And using the code above is the following allowed:
    B[0] = new Traceback2(i-1, 0);
    Any replies much appreciated. Thank you.

    1)
    public and private are access modifiers,
    void and String return type declarations.
    2)
    It's called "inheritance", and "bad design" as well.
    You should read the tutorials, you know?

  • Difference between Public Void and Public Int

    I was wondering what the difference was between 'public void' and 'public int'?

    Yeah,
    Given package forumTest;
    public class ReturnVoid
         public int returnInt()
         public void returnVoid()
    }compiling using the 1.4.2 reference compiler produces the following result:
    $ javac -d classes/ src/forumTest/ReturnVoid.java
    src/forumTest/ReturnVoid.java:6: missing return statement
            ^
    1 error

  • How many ways Checks can be reprinted, apart from FBZ5 and "Void and reprint" Options

    Hello All - Some times, when there is issue with Printer, Checks are not printed. In such a case, Users ask us how to print Checks.
    Some options I know are that (1) Checks can be reprinted through T Code - FBZ5 and
    (2) if Users are Ok with voiding Checks and use next available Check numbers, We use the option in the Variant - "Void and reprint" Option.
          Some Users are not happy with this Solution as they do not want to waste Checks.
    I am aware of only these 2 options. Can you please suggest me other alternatives we have to reprint Checks. Your valuable inputs are very helpful to us in this regard.
    Thanks

    Hi Hoysala,
    Please use the the FBZ5 as per attached screenshot for reprint check.

  • Mass Check void and other AP items

    Gurus,
    1) The requirement is to have the ability to mark list of check as voided and then off set the payment document to an escheatment GL account instead of clearing account. They currently have a very huge number of checks they would escheat.  I can't find any transactions that can meet mass void and post a clearing document on payment document to a different GL number.
    Is there a way we can do without having a ABAP development?
    2) When I creating an invoice in FB60, the payment term is defaulting from vendor master. But, the payment method  is not defaulting from vendor master. The payment method field is left blank though my vendor master has payment method.
    3) If I have multiple payment methods in vendor master and I have all payment methods in my proposal, which payment method the payment program considers in F110?  the first payment method that is in vendor master?

    HI Sri
    So, it will consider the order of payment proposal and not the order in vendor master?
    Yes you are correct
    So I have a vendor with cw and my proposal order is entered as wc, will it consider w or c? first one in proposal or first one in vendor?
    First one is in the proposal if that one is not available in vendor master ( nothing but payment document),  then it will go to next payment payment.
    if vendor has c and my invoice document is w and the proposal is w, will my proposal fails?
    Payment programme will check the payment method at payment document level. So defiantly your proposal will execute.
    Thanks
    Sreenivas

  • Void and Reissue Payments

    We have a scenario where a factor(associated with more than a hundred suppliers) has a payment returned from bank.
    For the above scenario there could potentially be hundreds of checks involved if a factor's payment is returned as payables processs a seperate ACH for each supplier attached to the factor.
    How can we customize or use the void and reissue program to enter a vendor number, factor number,factor site number or batch name, number(some sort of identifier) so as to prevent void and reissue each check.
    This is of high priority, any help, suggestions are greatly appreciated.
    Thanks in advance

    Hi Vetri
    following is how xml looks like:
    <PositivePayDataExtract>
    <OutboundPayment>
    - <PaymentStatus>
    <Code>VOID</Code>
    <Meaning>VOID</Meaning>
    </PaymentStatus>
    - <PaymentAmount>
    <Value>100</Value>
    </OutboundPayment>
    <OutboundPayment>
    - <PaymentStatus>
    <Code>ISSUED</Code>
    <Meaning>Printed</Meaning>
    </PaymentStatus>
    - <PaymentAmount>
    <Value>200.19</Value>
    </OutboundPayment>
    </PositivePayDataExtract>
    When the detail records are @ level of <Outboundpayment> group. Here this will go for 2 times like for
    example
    accountno123 check no0001 100 ABC Corp
    accountno234 check no0002 200 ABC Corp
    Now when I write SUM @level of <PositivePayDataExtract> group..So it goes for only ONCE.
    totaldetail_record_count=2 total_amount_300 ....[should be 200-100=100]
    When I write your syntax like @<PositivePayDataExtract> group it just check ONLY ONCE and at the first record it cheks for condition
    SUM((OutboundPayment/PaymentAmount[OutboundPayment/PaymentStatus/Code ='ISSUED']/Value))
    SUM(OutboundPayment/PaymentAmount/Value
    [OutboundPayment/PaymentStatus/Code=’VOID’])
    BUT it DOES NOT go to 2nd record.
    Bank wants SUM in one line..and still struggling..
    Any thoughts?
    thanks
    kp

  • Void and return help

    whats the difference of using void and using the return?
    i used last time the void and return, but the outputs of the two are the same

    CodeSniffer wrote:
    raychen wrote:
    Using return within a method that returns void is just a quick way to go all the way to the end of the method. It is a goto in disguise, but sometimes it may make your code cleaner.yeah, thats what i saw when im trying to figure out whats the diff of the twoAsking about the difference between void and return is like asking about the difference between being bald and leaving your house. The two are not in any way related, and there's no context in which you can choose between one and the other.
    You're going to have to clarify your question.
    Do you know what void means?
    Do you know what return does?
    If you answered yes to both, then I really have no idea what you're confused about.

  • Is there a way of passing a mixed cluster of numbers and booleans to teststand

    Hi,
    I have a labview VI that contains an output cluster containing both numeric and boolean results and would like to pass this to Teststand. At the moment I have coverted all my boolean results to  '1/0'  so that I can create a numeric array and can quite easily pass this to Teststand (using multiple numeric limit test). 
    Is there a way to pass mixed results to Teststand and write in the limits (example PASS and GT 5V) or do I have to stick with what I have?
    Chris

    Which test step type to use depends on what you have to analyze - a boolean condition? String? Number(s)? I can't tell you because I don't know what's in your cluster. If you click on the plus sign next to the parameter name "output cluster" you will see all paramters and their types, which are passed from the VI to TestStand.
    You can either create a variable for the whole cluster, or you can assign all or just some values from within the cluster to variables.
    The name of the variable (Locals.xxxxxxx... or FileGlobals.xxxxx...) ist what you type in the value field. You can also choose the variable from the expression browser by clicking on the f(x) button.
    Are you new to TestStand, do you know how to work with variables in TS?
    Maybe the attached picture gives you an example, there I am assigning the values from VI output "VoltageOutputArray" to the TS variable locals.VoltageMeasurement.
    This variable ist used again on the tab "Data Source" as the Data Source Expression.
    Regards,
    gedi
    Attachments:
    stepsettings.jpg ‏89 KB

  • In iMovie 11, how can you cut/paste a clip that has subtitles and actually have the subtitles get cut/pasted. When I try, the subtitles disappear into the void and I have to do the subtitling all over again.

    In iMovie 11, how can you cut/paste a clip that has subtitles and actually have the subtitles get cut/pasted. When I try, the subtitles disappear into the void and I have to do the subtitling all over again.

    If you think this is a bug, you can report it here:
    Apple - Mac OS X - Feedback

Maybe you are looking for

  • Is there any way for me to reverse tether my ipad in order to yse my computer's network connection via usb?

    I need to use an Ipad 2 running 5.1.1 without the use of ANY wireless data transfer, this means no bluetooth - 3g or Wi-Fi. I am aware of creating Wi-Fi hotspots, but there is absolutely no wi-fi option possible. Is this possible? If anyone could hel

  • Error in adgenjky.sh

    hi, anyone please help me out. [AutoConfig Error Report] The following report lists errors AutoConfig encountered during each phase of its execution. Errors are grouped by directory and phase. The report format is: <filename> <phase> <return code whe

  • Apple ID is disabled message when I access the App Store

    Whenever i try to download an app to my new iphone4 i get apple id is disabled.  I can access my Apple Id perfectly through the phone and the computer.  I can transfer apps from the computer to the phone perfectly, I just cant get through to the App

  • Help!!! Installed Sound Card driver does not support Direct Sound input

    I have just installed Premier Pro CS3 on a brand new PC. I am a new user and I am receiving a message "The installed sound card driver does not support direct sound input". PC is a 3 GHZ Intel Duo 4 G RAM 2 x 500 G HD Windows Home Vista Preminum I am

  • IPhoto Library Manager issues

    Last month I downloaded this software called Sponge to get rid of duplicated pictures. I had about 6000+ pictures then. Now when it found a duplicated pic, they went in the trash and I kept it in there till I got the job done. So then I opened my iPh