Click here to Skip to main content
15,914,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, how can I return 2 or above double data type values?

C#
private double calculateBalance(double ammt, double balance){
           double balbal = 0.0;

           try{
               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
               conn = DriverManager.getConnection("jdbc:odbc:BankSystem");
               select = "Select Branch From MalaysiaWithdraw where AccountNo = ?;";
               update = "Update MalaysiaWithdraw Set Balance = ? where AccountNo = ?";
               stmtSelect = conn.createStatement();
               stmtUpdate = conn.createStatement();
               pstmtSelect = conn.prepareStatement(select);
               pstmtUpdate = conn.prepareStatement(update);


               String branch = null;
               while(rsSelect.next()){
                   branch = rsSelect.getString("Branch");
               }
               if(branch.equalsIgnoreCase("Malaysia")){
                   double amou = ammt;
                   double myBal = balance;
                   balbal = balance - ammt;
                   long ref = (long)(Math.random()*1000000);
               }
               }

           catch(Exception ex){

           }

           return ???;
       }
Posted

Create an array with the two values and return the array. Something like:
Java
private double[] calculateBalance(double ammt, double balance){
// ...
    double[] amounts = new double[2];

// ...

    amounts[0] = ammt;
    amounts[1] = balance;

// ...
 
   return amounts;

However there are probably better ways to achieve the results you are aiming for, by using getters in your class to return specific values as and when required.
 
Share this answer
 
As suggested by Richard, you can make the function return a class as follows:

Java
class ReturnResult {
    private double first;
    private double second;

    public ReturnResult (double first, double second) {
        this.first = first;
        this.second = second;
    }

    public double getFirst() {
        return first;
    }

    public double getSecond() {
        return second;
    }
}


private ReturnResult calculateBalance(double ammt, double balance){
    
	// do something

    return new ReturnResult(firstDouble, secondDouble);
}

public static void main(String[] args) {

	double ammt = ???;	// some double value
	double balance = ???;	// some double value	
    ReturnResult result = calculateBalance(ammt, balance);
	// do something
}
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900