注意输出答案的时候换行:
import java.util.*; public class Main { public static void main(String[] args) throws Exception{ Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int n = sc.nextInt(), m = sc.nextInt(); double a = n, r = 0; while(m-- > 0){ r += a; a = Math.sqrt(a); } System.out.printf("%.2f\n", r); } } }