Crops

Untitled

May 23rd, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. public static void main(String[] args) {
  2. Scanner leer = new Scanner(System.in);
  3. int num1, num2, temp;
  4. System.out.println("Ingrese l primer numero");
  5. num1 = leer.nextInt();
  6. System.out.println("Ingrese el numero final");
  7. num2 = leer.nextInt();
  8. if (num1 > num2) {
  9. temp = num1;
  10. num2 = num1;
  11. num1 = temp;
  12. }
  13. System.out.println("Par o impar");
  14. temp = leer.nextInt();
  15. while (temp < 1 || temp > 2) {
  16. System.out.println("Par o impar");
  17. temp = leer.nextInt();
  18. }
  19. if (temp == 1) {
  20. if (num1%2==0){
  21. for (int i = 0; num1 < num2; i++) {
  22. num1 += 2;
  23. System.out.print(num1 + " ");
  24. }
  25. }else{
  26. num1 = num1 + 1;
  27. System.out.print(num1 + " ");
  28. for (int i = 0; num1 < num2; i++) {
  29. num1 += 2;
  30. System.out.print(num1 + " ");
  31. }
  32. }
  33. }else if (temp == 2){
  34. if (num1%2==0){
  35. num1 = num1 + 1;
  36. System.out.print(num1 + " ");
  37. for (int i = 0; num1 < num2; i++) {
  38. num1 += 2;
  39. System.out.print(num1 + " ");
  40. }
  41. }else{
  42. for (int i = 0; num1 < num2; i++) {
  43. num1 += 2;
  44. System.out.print(num1 + " ");
  45. }
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment