import java.util.Scanner; // Ejemplos de valores que puede ingresar el usuario // [A, B] Inc -> Resultado // [1, 10] +2 -> {1, 3, 5, 7, 9} // [1, 10] -2 -> Error // [10, 1] -2 -> {10, 8, 6, 4, 2} // [10, 1] +2 -> Error public class ConteoRangoDecremento { public static void main(String args[]) { Scanner teclado = new Scanner(System.in); System.out.print("Primer valor: "); int valorA = teclado.nextInt(); System.out.print("Ultimo valor: "); int valorB = teclado.nextInt(); System.out.print("Incremento: "); int incremento = teclado.nextInt(); if ( valorB >= valorA ) { if ( incremento > 0 ) { for ( ; valorA <= valorB; valorA += incremento ) System.out.print(valorA + ", "); System.out.println(); } else System.err.println("El incremento debe ser positivo"); } else { if ( incremento < 0 ) { for ( ; valorA >= valorB; valorA += incremento ) System.out.print(valorA + ", "); System.out.println(); } else System.err.println("El incremento debe ser negativo"); } } }