How do i return nothing in a "public int getNothing()" method ?

i'd like "getNothing" to return an int ONLY if "z" is true ... is that even possible ?
code :
  public int getNothing() {
        boolean z= trueOrFalse();
        int i = generator.nextInt(10);
        if (z=true){           
            return i;
Message was edited by:
jeroenQuant

but in this case it's kinda necessary ...It isn't possible, so it isn't necessary.
If getNothing() returns an int within a certain range, then you could return an int outside this range if trueOrFalse() is false. For example getNothing() could return a positive int when the condition is true and a -1 otherwise. The caller could detect the out of range value and act appropriately.
Another approach is to move the boolean test from the getNothing() method to its caller. Ie something like:public void test() {
    if(trueOrFalse()) {
        System.out.println(getNothing());
public int getNothing() {
    return generator.nextInt(10);
}

Similar Messages

  • How do you return more than one value from a method?

    say I have this:
    public static int myFunc(String inString)
         // I want to return two values from this method
    }yeah so how would i do that?

    If the two values are somehow related--like a person's name and his age--define a class that has those two values as member variables--for example, Person. But only if that class and the assocation of those two quantities makes sense as an entity in your program. Don't do it just to jam to quantities into one return.
    Or, if the two values are two of the same thing--person A's age and person B's age--then you can return an array or Collection.
    If it doesn't fit either of those two scenarios, then your method is trying to do too much unrelated stuff and you should break it into multiple methods. For example, calculating a Person's age based on his birthdate and today's date and calculating his Body Mass Index based on his height and weight. Those two quantities should NOT be returned together.

  • How do I cast a String to an int ?  HELP !

    Dear Java People,
    If I have a program that outputs a String of the time ie
    09:25
    How do I code in Java to check this String to see if it is greater than 12 o'clock and if so tack on a String of "PM'.....
    I tried
    if ((int) hours.getDisplayValue()> 12 )
    to attempt to add "PM" at the end of the String
    The error message says:
    "ClockDisplay.java": Error cannot cast java.lang.String to int at line 88, column 12
    below is the program
    Thank you in advance
    Stan
    * The ClockDisplay class implements a digital clock display for a
    * European-style 24 hour clock. The clock shows hours and minutes. The
    * range of the clock is 00:00 (midnight) to 23:59 (one minute before
    * midnight).
    * The clock display receives "ticks" (via the timeTick method) every minute
    * and reacts by incrementing the display. This is done in the usual clock
    * fashion: the hour increments when the minutes roll over to zero.
    * @author Michael Kolling and David J. Barnes
    * @version 2001.05.26
    public class ClockDisplay
    private NumberDisplay hours;
    private NumberDisplay minutes;
    private String displayString; // simulates the actual display
    * Constructor for ClockDisplay objects. This constructor
    * creates a new clock set at 00:00.
    public ClockDisplay()
    hours = new NumberDisplay(24);
    minutes = new NumberDisplay(60);
    updateDisplay();
    * Constructor for ClockDisplay objects. This constructor
    * creates a new clock set at the time specified by the
    * parameters.
    public ClockDisplay(int hour, int minute)
    hours = new NumberDisplay(24);
    minutes = new NumberDisplay(60);
    setTime(hour, minute);
    * This method should get called once every minute - it makes
    * the clock display go one minute forward.
    public void timeTick()
    minutes.increment();
    if(minutes.getValue() == 0) { // it just rolled over!
    hours.increment();
    updateDisplay();
    * Set the time of the display to the specified hour and
    * minute.
    public void setTime(int hour, int minute)
    //Exercise 3.19 This condition will insure that it will be a 12 hour clock
    if(hour > 12)
    hour = hour - 12;
    hours.setValue(hour);
    minutes.setValue(minute);
    updateDisplay();
    * Return the current time of this display in the format HH:MM.
    public String getTime()
    return displayString;
    * Update the internal string that represents the display.
    private void updateDisplay()
    if ((int) hours.getDisplayValue() > 12 )
    displayString = hours.getDisplayValue() + ":" +
    minutes.getDisplayValue() ;
    * The NumberDisplay class represents a digital number display that can hold
    * values from zero to a given limit. The limit can be specified when creating
    * the display. The values range from zero (inclusive) to limit-1. If used,
    * for example, for the seconds on a digital clock, the limit would be 60,
    * resulting in display values from 0 to 59. When incremented, the display
    * automatically rolls over to zero when reaching the limit.
    * @author Michael Kolling and David J. Barnes
    * @version 2001.05.26
    public class NumberDisplay
    private int limit;
    private int value;
    * Constructor for objects of class Display
    public NumberDisplay(int rollOverLimit)
    limit = rollOverLimit;
    value = 0;
    * Return the current value.
    public int getValue()
    return value;
    * Return the display value (that is, the current value as a two-digit
    * String. If the value is less than ten, it will be padded with a leading
    * zero).
    public String getDisplayValue()
    if(value < 10)
    return "0" + value;
    else
    return "" + value;
    * Set the value of the display to the new specified value. If the new
    * value is less than zero or over the limit, do nothing.
    public void setValue(int replacementValue)
    if((replacementValue >= 0) && (replacementValue < limit))
    value = replacementValue;
    * Increment the display value by one, rolling over to zero if the
    * limit is reached.
    public void increment()
    value = (value + 1) % limit;
    public class TryClockDisplay
    public static void main(String[] args)
    ClockDisplay clockDisplay_1 = new ClockDisplay();
    clockDisplay_1.setTime(17,40);
    System.out.println("\nThe time now is " + clockDisplay_1.getTime());
    clockDisplay_1.timeTick();
    clockDisplay_1.timeTick();
    clockDisplay_1.timeTick();
    clockDisplay_1.timeTick();
    clockDisplay_1.timeTick();
    clockDisplay_1.timeTick();
    clockDisplay_1.timeTick();
    System.out.println("\nThe time now is " + clockDisplay_1.getTime());

    String time = "09:25";
    String hrs = time.substring(0,2);
    int hrsInt = Integer.parseInt(hrs);
    if(hrsInt>12){
        time += "PM";
    System.out.println(time);                                                                                                                                                                                                                                                                                                                                       

  • How to print - when query returns nothing

    Hi All
    I have query...
    select sum((sum(nvl(ac.amtsourcedr,0))-sum(nvl(ac.amtsourcecr,0)))) as balance
    from fact_acct ac
    where ad_client_id=1000000
    and dateacct < '1/04/2010'
    and ac.account_id=1000432
    group by  ac.account_id
    I want to print zero when query returns nothing
    how to do that ..???
    thanking you in advance
    Regards
    gaurav

    use NVL
    select nvl(sum((sum(nvl(ac.amtsourcedr,0))-sum(nvl(ac.amtsourcecr,0)))),0) as balance
    from fact_acct ac
    where ad_client_id=1000000
    and dateacct < '
    and ac.account_id=1000432
    group by ac.account_idAnd yes you need to remove the Group By as stated by Toon, forgot to mention it
    Edited by: Karthick_Arp on May 27, 2010 4:04 AM

  • How to get return value from java and read by other application?

    i want to read return value from java and the other application read it.
    for example:
    public class test_return {
        test_return(){
        public int check(){
            return 1;
        public static void main(String args[]){
           new test_return().check();
    }from that class i make as jar file. How to read the return value (1) by other application?
    thx..

    If your installer is requiring some process it invokes to return a particular value on failure, then the installer is seriously broken. There are a bazillion commands your installer could invoke, and any of them could fail, which in turn could invalidate the entire install process, and any of them could return any value on failure. The only value that's consistent (in my experience) is that zero means success and non-zero means failure, with specific non-zero values being different in different programs.
    About the only control you have over the JVM's exit code is that if your main method completes without throwing an exception, the JVM will have an exit code of 0, and if main throws an exception (either explicitly or by not catching one thrown from below), it will be non-zero. I'm not even sure if that's guaranteed, but I would guess that's the case.
    EDIT: I'm kind of full of crap here. If you're writing the Java code, you can call System.exit(whatever). But nonetheless, if your installer requires certain exit codes from any app--java or otherwise--you have a problem.
    Edited by: jverd on Oct 29, 2009 1:27 AM

  • How to get return value from Java runtime.getRuntime.exec?

    I'm running shell commands from an Oracle db (11gr2) on aix.
    But, I would like to get a return value from a shell comand... like you get with "echo $?"
    I use a code like
    CREATE OR REPLACE JAVA SOURCE NAMED common."Host" AS
    import java.io.*;
    public class Host {
      public static int executeCommand(String command) {
        int retval=0;
        try {
            String[] finalCommand;
            finalCommand = new String[3];
            finalCommand[0] = "/bin/sh";
            finalCommand[1] = "-c";
            finalCommand[2] = command;
          final Process pr = Runtime.getRuntime().exec(finalCommand);
          pr.waitFor();
       catch (Exception ex) {
          System.out.println(ex.getLocalizedMessage());
          retval=-1;
        return retval;
    /but I do not get a return value... because I don't know how to get return value..
    Edited by: user9158455 on 22-Sep-2010 07:33

    Hi,
    Have your tried pr.exitValue() ?
    I think you also need a finally block that destroys the subprocess
    Regards
    Peter

  • IDVD 08 is a bummer. How do I return to an older version?

    I had iLife 04 on my Mac for ages, but I just bought and installed iLife 08.
    Mistake!
    IDVD 08 will not open any of my old iDVD projects; it just sits there with the beachball spinning or doing nothing at all. All the old projects now have the blue and white iDVD 08 icon, but they don't open. Likewise "Open Previous Project" doesn't work.
    So, I attempted to recreate some of my old projects in iDVD 08 by dumping the Quicktime movies that were originally used to create the old iDVD 4 projects (QuickTime movies that were exported from Final Cut Express), but I can't seem to drag and drop them into iDVD's background like I could with iDVD 4. When I drag the icon of the QT movie over into iDVD's window, the + sign does not appear, indicating that it's ready to drop, and when I let go of the mouse button, the QT movie's icon returns to the folder where the file resides.
    Most of the time, when trying to open or create any project, iDVD just sits there with its beachball spinning, or does nothing at all, so that I have to force-quit it (and then I trash the .plist).
    This version of iDVD seems like a real bummer. I can't get it to do anything.
    How do I return to iDVD 4? Can I Trash iDVD 08 and then reinstall iDVD 04 from the iLife 04 DVD?
    Tom

    Very rarely do I recommend reverting to an older version of iLife once the current version is already installed. But in your own situation, perhaps this is best ..... given the fact apple's iLife'08 isn't intended for a G4. You need a G5 or better for iMovie apparently within iLife 08. iDVD's system requirements call for at least a G4 733. But I haven't seen anyone post on this iDVD forum who has the latest version of iDVD successfully running on a G4.
    Use the following app at your own risk to remove iDVD:
    http://appzapper.com/
    Good luck!

  • How can I return to the top of an array indicator

    I have in my UI a 1D array indicator that I will navigate to and populate with different lists of items depending on other selections.  Always text elements.
    I have limited the number of visible rows to 20 max even though some lists will contain dozens if not hundreds of elements while others may have less than 10.  Problem is, if I scroll down the list for one population, then come back and the next list happens to have only 10 elements, the scroll bar is still way down where I had scrolled to earlier.  It is basically showing unpopulated positions in the array. (Not blank list items)
    How can I return the scroll position back up to the first element in the array when I populate it with a new list?  I looked through every property node and could find nothing.  Seems like there should be a method to refresh the display or it should go back to the top when you write a new value to it.
    Any thoughts?
    Thanks
    Doug
    "My only wish is that I am capable of learning each and every day until my last breath."

    Index Values, I think, is the property you are looking for.  Set the index to 0 to be at the top.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How can I return to use OSX (Yosemite) after installing Windows 8.1?

    How can I return to use OSX (Yosemite) after installing Windows 8.1?
    I cannot find Boot Camp on my iMac (late 2013) with windows installed. So I downloaded it, but I cannot run it because of an error (x64...). I tried to use my USB stick with bootcamp installed but nothing. When I turn my iMac on it starts automatically with windows. I tried to search it, but I found only the setup and it doesn't work. How can I get back to my APPLE iMac? How can I use OSX?
    Excuse me for the (maybe) uncorrect language, I speak Italian.

    Hello!
    You can start your Mac up with the [alt] (sometimes [option]) key pressed and you will get the Startup Manager.

  • How do you return the number of Rows in a ResultSet??

    How do you return the number of Rows in a ResultSet? It's easy enough to do in the SQL query using COUNT(*) but surely JDBC provides a method to return the number of rows.
    The ResultSetMetaData interface provides a method for counting the number of columns but nothing for the rows.
    Thanks

    No good way before JDBC2.0. u can use JDBC2.0 CachedRowSet.size() to retrieve the number of rows got by a ResultSet.

  • How can I return the current Date in Java?

    I am new to Java, and basically I want to know how I can return the current date as a variable, so for example, I have declared the following date variable
    private java.util.Date currentDate;How can I return the current date, do I have to write a method? To be more specific, I need to write a setMethod, that simply returns the current Date in Java.
    Please point me in the right direction.
    Thanks,

    If all you want is a date for printing or displaying, the easiest way is to use Date as shown below. If you need something more complex, look at the Calendar API.
    import java.util.Date;
    class DateEx
         public static void main(String args[])
              Date now = new Date();
              System.out.println(now);          
    }

  • My dock and top tool bar are both overlapping how do i return them to normal?

    My dock and top tool bar are both overlapping how do i return them to normal?

    Please read this whole message before doing anything.
    This procedure is a diagnostic test. It’s unlikely to solve your problem. Don’t be disappointed when you find that nothing has changed after you complete it.
    The purpose of the test is to determine whether the problem is caused by third-party software that loads automatically at startup or login, by a peripheral device, or by corruption of certain system caches. 
    Disconnect all wired peripherals except those needed for the test, and remove all aftermarket expansion cards. Boot in safe mode and log in to the account with the problem. Note: If FileVault is enabled on some models, or if a firmware password is set, or if the boot volume is a software RAID, you can’t do this. Ask for further instructions.
    Safe mode is much slower to boot and run than normal, and some things won’t work at all, including sound output and  Wi-Fi on certain iMacs. The next normal boot may also be somewhat slow.
    The login screen appears even if you usually log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin. Test while in safe mode. Same problem? After testing, reboot as usual (i.e., not in safe mode) and verify that you still have the problem. Post the results of the test.

  • How do I return a java.sql.Timestamp data type in a Web service?

    I'm new to workshop and java. I'm creating a mini application to simulate a real work Web Service (development environment is on an intranet). I was able to completely simulate the Web Services minus all date values.
    I'm using a standard weblogic workshop database controls that are feeding the various WebServices and their methods (Web services was generated from DB control). I get a java type not support error when I attempt to return a java.sql.Timestamp. I temporarily got around the problem by omitting all dates from the sql.
    However, we are at the point where we need the complete record.
    My two questions
    1) What java data type do I convert the java.sql.Timestamp to
    2) Where and how do I do it in workshop.
    Thanks in advance
    Derrick
    Source view from workshop looks something like this.
    public interface MyData extends DatabaseControl, com.bea.control.ControlExtension
    static public class dbOverallRec
    public String key;
    public String field1;
    public int field2;
    public java.sql.Timestamp create_date
    public dbOverallRec () {};
    *@jc:sq; rowset-name="OverallRowSet" statement::
    *select key, field1, field2 ,create_date from overall where key={KEY}::
    dbOverallRec getOverallByKey(String Key);
    * I had to omit the create_date to get it to work

    You should try changing java.sql.Timestamp to java.util.Calendar.
    java.util.Calendar maps to the dateTime type in XML Schema, and TIMESTAMP as a JDBC type.
    Regards,
    Mike Wooten

  • Running 'netstatt' On An Interface Alias Returns Nothing.

    Hi all,
    can some one please shed some light on this behavior. We defined some network interface aliases on a SunOS machine. Running a 'netstat' on the alias returns nothing, while running it on the actuall device name returns the expected stats.
    Is this behavior by design?
    How can you get stats running this cmd on an alias interface name?
    Thank you

    It did not solve the issue. But I found it.
    I sketch what I've done .. maybe others can use that info too.
    Reason: For traditional reasons, we use Apache Configs for Aliases ... no mapping within CF itself because up to CF9 those mappings are global. Howerver, for UNC mappings, this seems to be the bad way.
    Up to today, I had no idea how Apache and CF talk to each other on paths. Obvioulsy, CF ask Apache for a path resolution, but Apache as a System Service, was not able to verify the accessibility of the UNC path. Therefore, it or CF figured that they use the webroot of this vhost.
    When I ran Apache as Administrator, it could access the UNC and therefore Apache and/or CF returned the correctly expanded path. Of course, we don't run Apache with more rights than the System Service. Resetting Apache to that also returned the wrong UNC expansion.
    So, we now go with Mappings in CF itself. Since CF 10 allows for Per App Mappings, this is no longer a problem.
    Martin

  • How do I return to Safari 64-bit?

    Hello everyone,
    I just tried the new beta version of Coolirirs (http://www.cooliris.com/) and in the installation it said I had to run Safari in 32-bit mode so that I could use the Cooliris plugin.
    I clicked ok, so that the installation would configure Safari to run in 32-bit mode.
    And it runs in 32-bit mode with Cooliris enabled.
    But I don't want to quit Safari 64-bit so that I could use Cooliris.
    How do I return to Safari-64 bit mode?

    I wan't to be able to use Safari in 64-bit mode having Cooliris disabled.
    Again, I have to ask why, since you gain absolutely nothing at all. If you want to disable CoolIris, you need to move it to a folder named "Input Managers (Disabled)" in Home/Library/InputManagers.
    If your Mac is running in 64-bit mode, you can use the Get Info window on Safari to enable/disable running in 64-bit mode. However, if you do that and run it in 32-bit mode, you still can't run any Input Managers, as they require your Mac to be running in 32-bit mode. Like I said, you can't have it both ways, and you gain abolutely nothing by running in 64-bit mode.

Maybe you are looking for