using do-while loop to find prime and largest factor for 2-20

i’ve managed to completely it but there’s a small problem: it still prints 9 and 15 as prime even though i’ve got the largest factor. how should i change the code?

  int num=2,temp=0;
  do{
      for(int i=(num-1);i>=2;i--){
          if(num%i==0){
            System.out.println(num+" largest factor is "+i);
            break;
            }
        }
      boolean prime=false;
      for(int j = 2; j < num; j++){
            if(num % j == 0){
             break;
             }
            else{
                prime=true;
            }
         }
         if(prime == true){
            System.out.println(num+" is prime");
         }
      num++;
  }while(num<21);