RAWI TEJA SRIPALLI
RAWI TEJA SRIPALLI

Reputation: 13

executing return statement in Java

My desired output is to print You are in the main method @@@@You have declined to use this application under our terms please try again later But my return statement doesn't print anything What Am I missing? Here is my code

class demo { String applicationOutput(int eeter) {

    if (eeter == 1 )
    {
    System.out.println("You have opted to use this application underour terms");
        return "success and come";
    }
    else
    {
     System.out.println("@@@@You have declined to use this application under our terms");
        return"please try again later";

    }

 }  

} class demo1 {

 public static void main (String[] args)
    {
        System.out.println("You are in the main method");

demo d = new demo();
d.applicationOutput(0);
        }
}

Actual O/p; You are in the main method @@@@You have declined to use this application under our terms

Upvotes: 1

Views: 50

Answers (3)

Allanh
Allanh

Reputation: 507

In main you need to add the print element.

System.out.println(d.applicationOutput(0));

I advise you to have one return in your method, something like this:

String applicationOutput(int eeter) {
    String messageReturn = "";
    if (eeter == 1 )
    {
       System.out.println("You have opted to use this application underour terms");
       messageReturn=  "success and come";
    }
    else
    {
        System.out.println("@@@@You have declined to use this application under our terms");
        messageReturn = "please try again later";

    }
    return messageReturn;

 }  

Upvotes: 1

Mureinik
Mureinik

Reputation: 311163

Your main method ignores the return value of applicationOutput. If you want to print it, you'll have to do it there:

System.out.println(d.applicationOutput(0));

Upvotes: 0

Maurice
Maurice

Reputation: 7381

Use this in main

System.out.println(d.applicationOutput(0));

Upvotes: 1

Related Questions