Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8604053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:28:28+00:00 2026-06-12T02:28:28+00:00

Possible Duplicate: How to return multiple objects from a Java method? lets say N=

  • 0

Possible Duplicate:
How to return multiple objects from a Java method?

lets say N= a+b;
for a number N i want to generate the all possible values a and b. like
if N =7 a and b are (1+6),(2+5),(3+4).

i have coded this logic in a method.

static void sumofNum(int N){

        for(int a=1; a<N; a++){
                //a+b=N
                int b = N-a;
                System.out.println(a+","+b);
                int next =a+1;
                if(next==b | a==b)
                    return;
        }   
    }

i want to return (1,6),(2,5),(3,4) from this method. next for any N there can be more (a,b) combinations to be returned from this method.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:28:29+00:00Added an answer on June 12, 2026 at 2:28 am

    If you want to return them as ints, define a object that contains two ints (or abuse points as I have done below) and return a list of those objects. If you define your own object, just replace point with that.

    static ArrayList<Point> sumofNum(int N){
        ArrayList<Point> result = new ArrayList<Point>();
        for(int a=1; a<N; a++){
                //a+b=N
                int b = N-a;
            System.out.println(a+","+b);
            int next =a+1;
            if(next==b | a==b)
               result.add(new Point(a,b));
            }   
        return result;
        }
    

    You can get your results from the list with:

    results = sumofNum(7);
    int a = results.get(0).x; //a = 1
    int b = results.get(0).y; //b = 6
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to return multiple objects from a Java method? Is there any
Possible Duplicate: MySQL Select Multiple VALUES lets say i have a group of number
Possible Duplicate: How can I return multiple values from a function in C#? C#
Possible Duplicate: Return value from thread I want to get the free memory of
Possible Duplicate: returning multiple values from a function Suppose i have passed two values
Possible Duplicate: Select Records multiple times from table I want to have my query
Possible Duplicate: Returning multiple values from a C++ function /************************************************/ /* Name: premserv */
Possible Duplicate: Drawing multiple pixels/rectangles In my code i wrote a method that creates
Possible Duplicate: Will new return NULL in any case? Say i have a class
Possible Duplicate: SQL - how to SELECT multiple tables and JOIN multiple rows from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.