自己的代码一直在PTA上显示答案错误,如何解决?

img

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();

    for (int i = m; i <= n; i++) {
        String str = "";
        str += i + "=";
        int num = i;
        while(num % 2 == 0){
            str += 2 + "*";
            num /= 2;
        }
        while(num % 3 == 0){
            str += 3 + "*";
            num /= 3;
        }
        while(num % 5 == 0){
            str += 5 + "*";
            num /= 5;
        }
        while(num % 7 == 0){
            str += 7 + "*";
            num /= 7;
        }

        if (num % 2 > 0 && num % 3 > 0 && num % 5 > 0 && num % 7 > 0 && num > 1)
            str += num + " ";

        System.out.println(str.substring(0,str.length()-1));
    }
}

}

输出结尾无换行,你的有换行。

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();

        for (int i = m; i <= n; i++) {
            String str = "";
            str += i + "=";
            int num = i;
            while(num % 2 == 0){
                str += 2 + "*";
                num /= 2;
            }
            while(num % 3 == 0){
                str += 3 + "*";
                num /= 3;
            }
            while(num % 5 == 0){
                str += 5 + "*";
                num /= 5;
            }
            while(num % 7 == 0){
                str += 7 + "*";
                num /= 7;
            }

            if (num % 2 > 0 && num % 3 > 0 && num % 5 > 0 && num % 7 > 0 && num > 1)
                str += num + " ";

            if(i==n){
                System.out.print(str.substring(0,str.length()-1));
            }else{
                System.out.println(str.substring(0,str.length()-1));
            }
        }
    }
}

img

pta对java就是有问题,我icpc一直显示错,烦死人