返回列表 發帖
import java.io.*;
public class TQC201
{
   public static void main(String args[]) throws Exception
   {
      int x,y,z;
      int x0,y0;
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      System.out.print("請輸入 Z 可能的最大值:");
      z = Integer.parseInt( br.readLine() );
   
      if(z>1){
         x = -1; y=0;
         do{
           //這邊自己寫!!
           x0=x;
           y0=y;
           x++;
           y=(int)(3*Math.pow(x,2)+2*x+1);
         }while(y<z);
         System.out.println("當 X = " + x0 +"時, Y = " + y0 + ", Z = " + z +",符合 Y < Z 的條件");
      }else{
         System.out.println("當 X,Y 為正整數時, Y 恆大於等於 1, 故 Z = " + z +",無符合 Y < Z 的最佳解");
      }
   }
}

TOP

返回列表