Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. This should print:
  2.  
  3. Even numbers between 50 and 100:
  4. 50 52 54 .......
  5. Odd numbers between 50 and 100: //but it gets stuck here.
  6. 51 53 55 .......                //and doesn't print these.
  7.  
  8.  
  9.  
  10. /*
  11.  * Class: CS1301/19
  12.  * Term: Fall 2017
  13.  * Dr. Haddad
  14.  * Name: Ian Turner
  15.  * Lab 6
  16.  */
  17.  
  18. public class OddEven
  19.  {
  20.   public static void main(String[] args)
  21.    {
  22.    
  23.     int number = 50;
  24.    
  25.     for (int start = 0; start < 101; start++, number ++)
  26.      {
  27.       if (start == 0)
  28.        {
  29.         System.out.println("Even numbers between 50 and 100: ");
  30.        }
  31.       if (start < 51)
  32.        {
  33.        if (number % 2 == 0)
  34.          System.out.print(" " + number);
  35.          continue;
  36.        }
  37.      
  38.       number = 50;
  39.      
  40.       if (start == 51)
  41.        {
  42.         System.out.println("\nOdd numbers between 50 and 100: ");
  43.        }
  44.       if (start < 101)
  45.        {
  46.         if (number % 2 != 0)
  47.          {
  48.           System.out.print(" " + number);
  49.          }
  50.        }
  51.        
  52.        
  53.      }
  54.     }
  55.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement