- import java.util.*;
- public class jva201
- {
- public static void main(String arg[])
- {
- Scanner s = new Scanner(System.in);
- System.out.print("請輸入 Z 可能的最大值:");
- long z = Integer.parseInt(s.next());
- long tot=0;
- for(long x=1;x<=100000;x++)
- {
- long y = 3 * (x*x) + x*2 +1 ;
- if(y>z)
- {
- System.out.printf("當 x =%d 時, Y =%d , Z =%d,符合 Y < Z 的條件",x-1,tot,z);
- break;
- }
- tot=y ;
- }
- }
- }
複製代碼 |