- import java.util.Scanner;
- public class tqc201
- {
- public static void main(String args[])
- {
- Scanner s=new Scanner(System.in);
- System.out.print("請輸入Z可能的最大值: ");
- int z=s.nextInt();
- int temp=0;
- for(int x=1;x<=100000;x++)
- {
- int y=(x*x)*3+x*2+1;
- if(y>=z)
- {
- System.out.println("當x="+(x-1)+"時,y="+temp+",z="+z+",符合y<z的條件");
- break;
- }
- temp=y;
- }
- }
- }
複製代碼 |