The problem is that you are calculating the value 6303.75. if you add a statement where you subtract the value 0.000000000001 from the variable result then you will get the expected value 6303.749999999999.
The below code changes demonstrate how you can instead calculate 6303.749999999999:
public static void main(String[] args){
    double y1 = 0;  
    double y2 = 0;  
    double i = 0.025;  
    double n = 2;  
    double h1 = 2000; 
    double h2 = 4000; 
    y1 = Math.pow((1 + i), n) * h1;
    y2 = Math.pow((1 + i), n) * h2;
    double result =  y1 + y2;
    result -= (double)0.000000000001; // this line is the key to calculating the expected result
    System.out.println(result);
}
Output:
6303.749999999999