// Fencepost loops - aka "loop and a half" // Example: Print the numbers from 1 to N: // e.g. // 1, 2, 3, 4, 5 // where 5 is a number entered by the user import java.util.*; public class Fencepost { public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.print("Enter a number: "); int num = console.nextInt(); if (num>0) { System.out.print(1); } for (int i=2; i<=num; i++) { System.out.print(", " + i); } System.out.println(); } }