提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
如何查找和列出1到任何给定数字之间的奇数。
public class Main { public static void main(String[] args) { int limit = 50; /*来自 时代Java - N o w J a v a . c o m*/ System.out.println("Printing Odd numbers between 1 and " + limit); for(int i=1; i <= limit; i++){ //if the number is not divisible by 2 then it is odd if( i % 2 != 0){ System.out.print(i + " "); } } } }