import java.util.Scanner; //有這行才會有第十一行與第二十一行

public class F3

{

   public static void main ( String args[] )

   {

   Scanner input = new Scanner ( System.in ); //因為有第一行與第二十一行

   int x = 1 ; //初始化為1 因為要從1開始加

   int y ; //這是給使用者輸入的 所以不用給他初始化

   int z = 0 ; //這裡一定要輸入0 不然他不知他的設定值

   System.out.printf("請輸入數字:");

   y = input.nextInt(); 

      //注意 不是input = nextInt() 因為這樣沒有東西可以讓使用者輸入

      while( x <= y )

      {

      z = z + x ;

      x++; //不使這個程式變成無限迴圈

      }

      System.out.print(z); //不能打printf 因為裡面要有溢出字元 //不要打在迴圈裡

   }

}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 a25561970 的頭像
    a25561970

    萬花筒

    a25561970 發表在 痞客邦 留言(0) 人氣()