Advertisement
letsdoitjava

Bounds_Problem

Jun 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. package Bounds;
  2. import java.util.Scanner;
  3. public class Bounds_Problem {
  4.  
  5.     public static void main( String[] args ) {
  6.  
  7.         // Declare Variables
  8.         int starting_number = 0, step = 0, upper_bound = 0, i = 0;
  9.  
  10.         // Read in from user starting number, step size and upper bounds.
  11.         Scanner startInput = new Scanner( System.in );
  12.         System.out.println( "Please enter a staring number. " );
  13.         starting_number = startInput.nextInt();
  14.         Scanner stepSize = new Scanner( System.in );
  15.         System.out.println( "Please enter a step size. " );
  16.         step = stepSize.nextInt();
  17.         Scanner upperBound = new Scanner( System.in );
  18.         System.out.println( "Please enter an upper bounds. " );
  19.         upper_bound = upperBound.nextInt();
  20.  
  21.  
  22.         // Loop terminates when the starting number is greater than or equal to upper bounds.
  23.         while( starting_number < upper_bound ) {
  24.  
  25.             // Print out numbers after calculations.
  26.             System.out.print( starting_number + " " );
  27.             starting_number = starting_number + step;
  28.             // Counter
  29.             i++;
  30.  
  31.             // When counter is equal to 10 print newline
  32.             if( i == 10 ) {
  33.                 System.out.print( "\n" );
  34.                 i = 0;
  35.             }
  36.         }
  37.         stepSize.close();
  38.         upperBound.close();
  39.         startInput.close();      
  40.     }    
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement