2012-12-12 110 views
-3

我正在創建掃描儀測試。我已經設法打印偶數1-50。我想要做一個掃描器代碼,以便當用戶輸入8時,它將打印8-50的所有偶數。偶數掃描器代碼

import java.util.Scanner;

公共類ModulusCalculation {

public static void main(String[] args) 
{ 
    int endLimit = 50; 

    System.out.println("WE ARE GOING TO PRINT EVEN NUMBER FROM 1 AND " + endLimit); 
    Scanner input = new Scanner(System.in); 
    for (int startingPoint = 1; startingPoint <= endLimit; startingPoint++) 
    { 
     if (startingPoint % 2 == 0) 
     { 
      input.nextLine(); 
      System.out.println(+startingPoint); 
     } 
    } 

} 

}

+0

以及我試圖使它的工作就像那一刻它將只打印返回所有值從1-50 /不需要是粗魯正版,並試圖獲得幫助 –

回答

0

不需要讀取input.nextLine();在for循環中使用

步驟1:讀起始整數值

步驟2:對(INT起點= startinteger;起點< = endLimit;起點++)

STEP3:打印所有的偶數基於for循環內的條件

+0

感謝您的幫助 –

+0

@JazBansal不客氣 –