2 test cases are not passing

hello sir , here is the code of my question number 2 in arrays assignment . and i cant find out why my solution is not passing 2 test cases.

import java.util.*;
public class Main {
public static void main(String args[]) {

 Scanner s = new Scanner(System.in);
 String str = s.nextLine();
 String res ="";
 for(int i=0;i<str.length();i++){

	int a=Character.getNumericValue( str.charAt(i) );	
	 int b = 9-a;

	 if(res == "" && b==0 ){
     
    if(a==0){
		
		
	}
	if(b==0){
		
		
	}

	 } 
    else{
	 if(a>b){
		res= res+ b;
	 }else{
		 res = res+a;
	 }
	}

  }
 System.out.println(res);
 
}

}

input 9017 .
output 9012.
but your code gives 012 .

Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn’t contain leading zeroes. for example N is 956 then output is 943.