Advertisement
StefanTobler

Lesson 24 Activity 3

Oct 27th, 2016
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. /*
  2.  * Lesson 24 Coding Activity 3
  3.  * Input an int between 0 and 100 and print the numbers between it and 100.
  4.  * If the number is not between 0 and 100 print "error".
  5.  * Print 20 numbers per line.
  6.  *
  7.  *     Sample Run 1:
  8.  *        
  9.  *         Enter a number between 0 and 100:
  10.  *         30
  11.  *         30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
  12.  *         50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
  13.  *         70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
  14.  *         90 91 92 93 94 95 96 97 98 99 100
  15.  *        
  16.  *
  17.  *    Sample Run 2:
  18.  *        
  19.  *         Enter a number between 0 and 100:
  20.  *         105
  21.  *         error    
  22.  *
  23.  *
  24.  */
  25.  
  26. import java.util.Scanner;
  27. import java.lang.Math;
  28.  
  29. class Lesson_24_Activity_Three {
  30.     public static void main(String[] args)
  31.      {
  32.       Scanner scan = new Scanner(System.in);
  33.       System.out.println("Enter a number between 0 and 100:");
  34.       int n = scan.nextInt();
  35.       int c = 0;
  36.       if(n < 100 && n > 0)
  37.       {
  38.         for (int i = n; i <= 100; i++)
  39.         {
  40.            if (c%20 == 0)
  41.            System.out.println();
  42.          System.out.print(i + " ");
  43.          c++;
  44.         }
  45.       }
  46.       else
  47.         System.out.println("error");
  48.       }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement