Return statement without parameter

What the return statemet return?
package examples;
import nsga2.MultiObjectiveProblem;
/*  Test problem BNH
# of real variables = 2
# of bin variables = 0
# of objectives = 2
# of constraints = 2
public class bnh extends MultiObjectiveProblem{
     public void test_problem (double []xreal, double []xbin, int [][]gene, double []obj, double []constr)
         obj[0] = 4.0*(xreal[0]*xreal[0] + xreal[1]*xreal[1]);
         obj[1] = Math.pow((xreal[0]-5.0),2.0) + Math.pow((xreal[1]-5.0),2.0);
         constr[0] = 1.0 - (Math.pow((xreal[0]-5.0),2.0) + xreal[1]*xreal[1])/25.0;
         constr[1] = (Math.pow((xreal[0]-8.0),2.0) + Math.pow((xreal[1]+3.0),2.0))/7.7 - 1.0;
         return;
}

return does two things: It causes the method to end immediately (returns flow of control to the caller), and it specifies what value will be passed back to the caller (returns the method result to the caller). However, when no value is provided, it does only the first--causes the method to end immediately.

Similar Messages

  • Recursion with Return instruction without parameter

    Please I have a doubt about following code:
    public void solveTowers( int disks, int sourcePeg, int destinationPeg,
    int tempPeg )
    if ( disks == 1 )
    System.out.printf( "\n%d --> %d", sourcePeg, destinationPeg );
    return;
    solveTowers( disks - 1, sourcePeg, tempPeg, destinationPeg );
    System.out.printf( "\n%d --> %d", sourcePeg, destinationPeg );
    If I enter witch amount variable DISK = 3
    I'd like to known: Why ouput after perform the code is
    1--->3
    2--->3
    1--->3 ?
    I didn't get it about the mechanism logical of RETURN instruction !!!
    Please, some could me help and explain about with mechanism
    OBS: An draw or design it will be helpfull for me understant
    A lot of thanks
    Gmourad

    You didn't mention other parameters of your recursive method, so I am not guessing but here is an easier example.
    public class Test{
         public void resursive(int num) {
              if (num == 1) {
                   System.out.println(num);
                   return;
              resursive(--num);
              System.out.println(num);
        public static void main(String[] args) {
              int num = 3;
              Test myTest = new Test();
              a.resursive(num);
    1
    1
    2
    recursive(3) -> recursive(2)                                          // print 2
                    recursive(2) -> recursive(1)              // print 1
                                    recursive(1) -> // print 1It would print the last one first because the upper one would call itself first before print out the value.

  • Retrieve Crystal SQL statements without first submitting parameter values?

    Hi,
    I am retrieving SQL statements for Crystal reports without issue, but a large number of our reports have parameters and for these the following error is thrown when I try to retrieve the SQL statement via RAS using getSQLStatement():
    com.crystaldecisions.sdk.occa.report.lib.ReportSDKServerException: Missing parameter values.---- Error code:-2147217394 Error code name:missingParameterValueError
    I have a large number of reports I'd like to pull SQL for, so it's not feasible to have my script push parameter values to each and every report.  Is there a way to retrieve SQL statements without first pushing parameter values?
    Thanks

    Hello Jeremy.
    I found a Knowledge Base article that deals with the "Error code:-2147217394 Error code name:missingParameterValueError" error that you mention.  Perhaps you could take a look at the following KBase Article in the Service MarketPlace and see if any of it applies to your situation:
    KBase number: 1420593
    I also found KBase number "1420501 - Report parameters ignored when set by Java post processing code" that seems to deal with the same problem.
    Regards.
    - Robert

  • Procedure with Return statement

    Hi,
    Below is my code. Am trying to return a value without a out parameter in the procedure. Is out parameter is mandatory to return a value in a procedure. Please help.
    CREATE OR REPLACE
    PROCEDURE P123(
        PID NUMBER)
    AS
      VCOUNT NUMBER;
    BEGIN
      SELECT COUNT(*) INTO VCOUNT FROM EMP WHERE EMPNO=PID;
      IF (VCOUNT=1) THEN
        RETURN 1;
      ELSE
        RETURN 0;
      END IF;
    END;Thanks

    Hi,
    When a procedure encounters a RETURN statement, it Returns the control, back to the calling program. In the below example, P1 is calling P2. When P2 encounters a RETURN statement, control is passed back to P1 procedure and "Out of p2 procedure" message is printed as per below example.
    Note: No further execution happens in P2 procedure when return is encountered.
    create or replace procedure P1
    as
    Begin
    p2;
    dbms_output.put_line('Out of the p2 procudure");
    end;
    create or replace procedure P2
    as
    begin
    dbms_output.put_line('calculation 1");.......
    return;
    dbms_output.put_line('calculation 2");
    end;
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Carriage Return in Input Parameter

    Hello,
    My report is passed an address string in a parameter like: name addressline1 city state zip.
    I want to display this like:
    name
    addressline1
    city state zip
    In that past, when I have name, address1, and citystatezip in separate fields I use a formula:
    name + chr(10) + addressline1 + char(10) + city state zip.
    However, I tried adding the chr(10) to my input parameter string and it just gets printed in my string.
    Is there a way to get carriage returns in a parameter address string?
    Thanks! Linda

    Somehow I figured this out.

  • Missing return statement - Java noob here

    Hi to everyone! I'll just like to ask if anyone of you can check out my code and see why I can do to correct this 'Missing return statement' problem with my code.
    From what I've been noticing, the compiler returns this statement when the return statements are inside conditional clauses. Usually I've been able to remedy it by storing it into another variable that's been instantiated outside my usual 'if' statements. But this time, it was my first time to use a 'try' statement since FileReader and FileWriter won't work without it. I tried to use the same remedy but it just doesn't work. Here's the part of the code I'm having problems with:
    public String[] sortWordList()
             try
                  FileReader fReader = new FileReader("initlist.txt");
                  BufferedReader bReader = new BufferedReader(fReader);
                  String output = bReader.readLine();
                  String[] words = output.split(",");
                  for(int counter1 = 0; counter1 < words.length; counter1++)
                        for(int counter2 = counter1 + 1; counter2 < words.length; counter2++)
                                  if(words[counter2].compareToIgnoreCase(words[counter1]) < 0)
                                       String temp = words[counter1];
                                       words[counter1] = words[counter2];
                                       words[counter2] = temp;
                   String temp = "";
                   for(int counter1 = 0; counter1 < words.length; counter1++)
                        FileWriter fWriter = new FileWriter("initlist.txt");
                       fWriter.write(words[counter1] + "," + temp);     
                       fWriter.close();
                       temp = bReader.readLine();
                   String output2 = bReader.readLine();
                  String[] words2 = output.split(",");
                  return words2;
             catch(IOException ioe)
        }The compiler points the 'Missing return statement' at the last bracket.
    BTW, just for those who are wonder what we're making, our teacher gave us a machine project where we have to make a basic dictionary (words only, we'll be doing the definitions and other stuff that's associated with the word some other time I think) with input and sort functions.
    Thanks guys!
    - Alphonse

    T.B.M wrote:
    By doing this, we're subverting the exception mechanism and totally defeating the purpose of exceptions. If you're going to catch an exception, you should handle it. Just smothering it and returning null is not handling it. If you're not going to handle it, then don't catch it, or else catch it and wrap it in a more layer-appropriate exception and re-throw.Then ideally there should be some *"return String[];"* statement inside "catch", not after it.No. Not unless there's some meaningful default value to use when the file can't be read, which does not appear to be the case here.
    If you return null, or an empty String[], then the caller will have to do an if test to know that something went wrong and that the method failed to do what it was supposed to do, and then what is the caller supposed to do in that case? The point of exceptions is to avoid those explicit tests for errors and let the "happy path" code just go on under the assumption that things are fine. If something goes wrong, an exception will be thrown and the happy path code will stop excuting, without having to explicitly test for an error condition.

  • Why 2 castings in return statement of entrySet() of HashMap?

    Hi
    When looking through the code of the HashMap class in jdk 1.5 in Eclipse 3.2 I see the following:
    public Set<Map.Entry<K,V>> entrySet() {
    Set<Map.Entry<K,V>> es = entrySet;
    return (es != null ? es : (entrySet = (Set<Map.Entry<K,V>>) (Set) new EntrySet()));
    Here I am wondering why there in the return statement are 2 (two) castings:
    return (es != null ? es : (entrySet = (Set<Map.Entry<K,V>>) (Set) new EntrySet()));
    , where I think of (Set<Map.Entry<K,V>>) (Set)
    Can anyone give me a good explanation to this?
    Thank you!

    Hi,
    you're right: the casts are not really necessary at all, since an assignment from a raw type is possible without an explicit cast. Either with or without the casts, the compiler will issue an "unchecked" warning.
    (And, of course, a single cast to the target type would also work here.)
    The "correct" way to fix the code would be to make the inner class EntrySet a parameterized class by deriving it from AbstractSet<Map.Entry<K,V>>. Then all "unchecked" warnings would automatically disappear.
    My guess is that by the time the developer generified the HashMap, there where still compiler bugs preventing him from declaring inner classes such as EntrySet correctly. Since then, nobody's touched the code again.

  • Doubt on Return statement

    Hi,
    IN the code below,
    I need to return a Double value. That Double value is declared and calculated with in IF condition.
    But, If i keep return statement with in if condition, i get "MIssing return statement error". IF i keep Return statement outside if(), I get "symbol c not found error".
    How do i fix this?
    private Double calculate(Double a, BigDecimal b) {  
            if(!((null == a)&&(null == b))){  
            //do some calculation  
            Double c = Double.valueOf(b.doubleValue());  
            return c; ---> Getting error right here.  (Can't find symbol c error.)  
       }  please help

    gimbal2 wrote:
    900637 wrote:
    Is there any solution for this?Perhaps you need two return statements.This depends whether <tt>a</tt> and <tt>b</tt> can be null because of business rules or programming errors.
    If the latter I'd not care for the NPE or just throw my own NPE from the else path telling which parameter has been null .
    If business rules forcs you to handle null values these rules must provide a solution for that case to be implemented in the else path.
    bye
    TPD

  • Unreachable statement error occured while using return statement.

    Consider this code
    class q25{
         public static void main(String args[]){
              amethod(args);
         public static void amethod(String args[]){
              String str;
              try{
                   str = "Hello "+args[0];
                   System.out.println(str);
                   System.out.println("Returning to caller");
                   System.exit(0);
              catch(Exception e){
                   System.out.println("Exception ocured");
                   System.exit(0);          
              finally{
                   System.out.println("In finally");
              System.out.println("At the end of method");     
    }Above code compiles and runs successfully without any errors.
    Now consider below code which is same as above one except "System.exit(0)" statements were replace by "return" statements. Below code when compiled gives error as
    "q25.java:22: unreachable statement
    System.out.println("At the end of method");
    ^
    1 error"
    One thing i didn't understood in this context that, the above code when compiled should get same error as stated above. But not. It is obvious that presence of System.exit(0) must generate unreachable statement same as when it is replaced by "return" statement. What is the difference in getting the error for above but not for below code. Pls anyone help.
    class q25{
         public static void main(String args[]){
              amethod(args);
         public static void amethod(String args[]){
              String str;
              try{
                   str = "Hello "+args[0];
                   System.out.println(str);
                   System.out.println("Returning to caller");
                   return;
              catch(Exception e){
                   System.out.println("Exception ocured");
                   return;     
              finally{
                   System.out.println("In finally");
              System.out.println("At the end of method");     
    }

    warnerja wrote:
    masijade. wrote:
    Since you have a "return" in both the try and the catch portions of the try/catch block *(the second of which you should never do)* , anything thing that comes after the try/catch/finally blocks will be unreachable.That is not true. There are plenty of reasons to return from a catch block. If you handle the exception instead of rethrowing it or another exception, then you'll need a return somehow, either there or after the catch block. What you should never do is "return" in a finally block, because that will mask any exception in flight about to be thrown to the caller.Perhaps masijade's use of never is too strong, but I too prefer/tend to avoid using return anywhere in try/catch/finally to avoid potential gotchas. Consider:
    public class TryCatchFinally
      public Data process(String s)
        Data returnData = new Data();
        try
          returnData.value = Integer.parseInt(s);
          returnData.message = "Success";
          return returnData;
        catch (Exception ex)
          returnData.value = -1;
          returnData.message = "Fail";
          return returnData;
        finally
          returnData.value = 42;
          returnData.message = "?";
      public static void main(String[] args)
        TryCatchFinally demo = new TryCatchFinally();
        Data d = demo.process("2");
        System.out.println(d.message + ": " + d.value);
        d = demo.process("2.1");
        System.out.println(d.message + ": " + d.value);
      class Data
        int value = 0;
        String message = "";
    }

  • Help with a return statement please!

    hey, just hoping somone can help me with this return statement
    i have to add a method called "specialReport" this method takes a year as it's parameter. if the parameter is not a year between 1930 and 1969 inclusive it displays an error message, "not a valid year"
    if the parameter is a valid year, then it compares the parameter with the year field. if they are the same, and is the movie has been rented at least five times, the method will display the message "a good year for movies" if the years are different or the movie has NOT been rented at least five times, the method displays the message "try a different year"
    btw, the Year field is : yearReleased
    all help is very much appreciated!

    public void specialReport(int year){
       //add functionality to process here
       return;
    }

  • HT201272 Can I still download my previous purchase from my previous country (returning back) without repurchasing it?

    Can I still download my previous purchase from my previous country (returning back) without repurchasing it? I'm curious since my purchase of iPhoto has disappeared on my mac, will I be able to get it again without repurchasing?

    How are you trying to redownload them e.g. you are using the Purchased link under Quicklinks on the right-hand side of the iTunes store home page on your computer's iTunes :
    If you are in a country where music can be redownloaded then that should let you redownload them from the store.
    If they redownload in the same shortened state then you can contact iTunes Support : http://reportaproblem.apple.com
    If the 'report a problem' link doesn't work then you can try contacting iTunes support via this page : http://www.apple.com/support/itunes/contact/- click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • Which return statement i should use.

    I have a problem regarding the return statement that i should use in the following programe.
    //Printing random letters without vowels
    public class Capitals {
      public char mymethod (){
         int counter = 0;               // Counter for number of capitals generated.
        int numberToGenerate = 20;     // Number of capitals to generate.
        char symbol = 0;               // Variable to store a random character.
        // While there are still letters to generate:
              while( counter < numberToGenerate ) {
          // Generate a random symbol between A and Z:
          // This relies on the fact that the codes for the letters are in a
          // contiguous sequence from 'A' to 'Z'. If we add 1 to 'A' we get the
          // code for 'B', if we add 2 we get 'C', and so on. Thus to create a
          // random capital letter from 'A' to 'Z' we can add a random integer
          // between 0 and 25 to 'A'.
          symbol = (char)(26*Math.random() + 'A');
          switch(symbol) {
            //Vowels ignored:
            case 'A':
            case 'E':
            case 'I':
            case 'O':
            case 'U':
              break;
            default:
              //Consonant displayed:
              System.out.print(symbol + " ");
              counter++;
              break;
    return symbol; // My Problem is here <<<<<<<<<<<<<
    public static void main(String args[])   {
    Capitals myCapitals=new Capitals();
    myCapitals.mymethod();
    }Can anyone kindly guide as to what return statement i should use in mymethod() so that it can be called in the main.
    thanks

    return types are not compulsory. there's a school of though amongst some 'C' programmers, that all functions should return something, even if the returned value is of no interest most of the time. some C compilers even force this behaviour, I think it's part of some standard but I can't remember now
    anyways, methods that have something to return need a return type, those that don't can be void. if you're invoking a method just to get it to do some work, it can probably be void, but if it's doing some computation for you you'll likely want to know the result, hence it must return something

  • Import Statement without ID Specification

    There is an import statement
    IMPORT tab g_acc_tab FROM MEMORY.
    While UCChecking it.. it saying that
    import statement without id specification is only used for the sake of r/2 ......
    Can i Comment it ? If so won't my application  go into dump while running on 6.0cc???

    It has to do with packages. Most java classes are in a package, the name of which must conform to its place on the filesystem relative to the classpath. By that I mean that if you have com.mystuff.One.java, it must be in a folder com/mystuff where com is located somewhere in the classpath.
    What you've done is a little different. I'm assuming a couple of things:
    1. you have no package declaration at the top of one.java or two.java
    2. you have the current directory "." in your classpath.
    Java has the concept of the "default package", which covers classes without a declared package, and in your case is the current directory.
    So when you're in c:\sourcefolder and run the compiler, then "."="c:\sourcefolder", and that directory is part of the default package. No import statements are necessary for classes that are in the same package. This is why two.java can call methods in one.java without an import statement.
    When you run your jsp, the "current directory" part of your classpath is not c:\sourcefolder, but some other value (probably the directory you start your jsp engine from) You will have to import all non-java-library classes because the jsp itself becomes a java class, with a package that is determined by the jsp engine.

  • Problems with asynchronous(?) function call before return statement

    I have a function as following inside a class deriving from CustomNode:
    override protected function create () : Node {
                    parseContent();
                    return group;
            }parseContent() executes a HttpRequest and then a PullParser. At least that's what it should do. But actually, it doesn't. Is this because the HttpRequest is asynchronous and is "cancelled" because of the return statement? Or can't this be the problem?

    You would have to update or create the view in the finally block of the onOutput: or onInput methods within the request.
    You could also try
    var viewContent: Node;
    override protected function create () : Node {
                    parseContent();
                    FX.deferAction(function():Void{
                           viewContent = group;
                    return Group{ content: bind viewContent }
            }I never tried that, but it might work.
    Another option is to bind the parsed content to whatever view you are pushing it to. Then whenever the request is done, the view will populate its content on the change of the variable where the content is stored.
    Example:
    var allTables: TableModel[];      
    //***************start of table list decleration****************************\\
    public var list: SwingJList = SwingJList {
        var shortcutKey: Boolean = false;
        focusTraversable: true
        selectedIndex: 0
        action: function(){
            FX.deferAction(function():Void{
                openButton.fire();
        items: bind for( table in allTables ){
            table.name
    var searchDataXml = xmlGenerator.generateSearchXMLString(searchData);
    var contentLength: Integer = searchDataXml.getBytes().length;
    def postRequest: HttpRequest = HttpRequest {
        location: "{WEB_APPLICATION_REQUEST_URL}searchData/?database={DATABASE_KEY}";
        method: HttpRequest.POST;
        headers: [
                HttpHeader {
                    name: HttpHeader.CONTENT_TYPE;
                    value: "application/xml";
                HttpHeader {
                    name: HttpHeader.CONTENT_LENGTH;
                    value: "{contentLength}";
        onStarted: function() {
            println("onStarted - started performing method: {postRequest.method} on location: {postRequest.location}");
        onConnecting: function() { println("onConnecting") }
        onDoneConnect: function() { println("onDoneConnect") }
        onWriting: function() { println("onWriting") }
        onOutput: function(os: java.io.OutputStream) {
            try {
                os.write(searchDataXml.getBytes());
            } finally {
                println("onOutput - about to close output stream.");
                os.close();
                os.flush();
        onToWrite: function(bytes: Long) { println("onToWrite - entire content to be written: {bytes} bytes") }
        onWritten: function(bytes: Long) { println("onWritten - {bytes} bytes has now been written") }
        onDoneWrite: function() { println("doneWrite") }
        onReadingHeaders: function() { println("onReadingHeaders") }
        onResponseCode: function(code:Integer) { println("onResponseCode - responseCode: {code}") }
        onResponseMessage: function(msg:String) { println("onResponseMessage - responseMessage: {msg}") }
        onResponseHeaders: function(headerNames: String[]) {
            println("onResponseHeaders - there are {headerNames.size()} response headers:");
            for (name in headerNames) {
                println("    {name}: {postRequest.getResponseHeaderValue(name)}");
        onReading: function() { println("onReading") }
        onToRead: function(bytes: Long) {
            if (bytes < 0) {
                println("onToRead - Content length not specified by server; bytes: {bytes}");
            } else {
                println("onToRead - total number of content bytes to read: {bytes}");
        onRead: function(bytes: Long) {
            // The toread variable is non negative only if the server provides the content length
            def progress =
            if (postRequest.toread > 0) "({(bytes * 100 / postRequest.toread)}%)" else "";
            println("onRead - bytes read: {bytes} {progress}");
        var parser = new XmlPullParser();
        onInput: function(is: java.io.InputStream) {
            // use input stream to access content here.
            // can use input.available() to see how many bytes are available.
            try {
                allTables = parser.processResults(is);
            } finally {
                is.close();
        onException: function(ex: java.lang.Exception) {
            println("onException - exception: {ex.getClass()} {ex.getMessage()}");
        onDoneRead: function() { println("onDoneRead") }
        onDone: function() { println("onDone") }
    postRequest.start();
    } In this case an array of tableModel names are bound to the list view.
    When the httprequest ends, it sets the parsed tableModel array to the array declared in this class.
    The list view will populate the table names from the array when the request finishes.

  • Can we use return statement in procedure?

    Can we use return statement in procedure or we can use more than one return statement in procedure?

    HamidHelal wrote:
    NOReally? Did you at least test it? You can use RETURN in procedure or in anonymous PL/SQL block. The only restriction is you can't specify return value:
    SQL> begin
      2      dbms_output.put_line('Before return');
      3      return;
      4      dbms_output.put_line('After return');
      5  end;
      6  /
    Before return
    PL/SQL procedure successfully completed.
    SQL> create or replace
      2    procedure p1
      3      is
      4      begin
      5          dbms_output.put_line('Before return');
      6          return;
      7          dbms_output.put_line('After return');
      8  end;
      9  /
    Procedure created.
    SQL> exec p1;
    Before return
    PL/SQL procedure successfully completed.
    SQL> begin
      2      dbms_output.put_line('Before return');
      3      return 99;
      4          dbms_output.put_line('After return');
      5  end;
      6  /
        return 99;
    ERROR at line 3:
    ORA-06550: line 3, column 5:
    PLS-00372: In a procedure, RETURN statement cannot contain an expression
    ORA-06550: line 3, column 5:
    PL/SQL: Statement ignored
    SQL> create or replace
      2    procedure p1
      3      is
      4      begin
      5          dbms_output.put_line('Before return');
      6          return 99;
      7          dbms_output.put_line('After return');
      8  end;
      9  /
    Warning: Procedure created with compilation errors.
    SQL> show err
    Errors for PROCEDURE P1:
    LINE/COL ERROR
    5/9      PL/SQL: Statement ignored
    5/9      PLS-00372: In a procedure, RETURN statement cannot contain an
             expression
    SQL> SY.

Maybe you are looking for