Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Bounds;
- import java.util.Scanner;
- public class Bounds {
- public static void main(String[] args) {
- // MP2 Bounds a java program that reads input from user and
- // prompts user for 3 numbers: starting number, upper bound, step size
- // printing no more than 10 numbers per line
- // @ author Renee Waggoner
- int startingNumber, upperBound = 0, stepSize = 0, count = 0;
- // prompting user for starting number
- Scanner input = new Scanner(System.in);
- System.out.println("Enter starting number: ");
- // obtaining starting number input
- startingNumber=input.nextInt();
- // prompt for upper bound number from user and obtaining upper bound number from user
- System.out.println("Enter upper bound number: ");
- upperBound = input.nextInt();
- // prompting for step size from user and obtaining step size from user
- System.out.println("Enter step size: ");
- stepSize = input.nextInt();
- // spacing for printed numbers
- System.out.print(startingNumber + " ");
- // after printing every number in loop, count by 1
- count++;
- // equals is not used here to stop numbers from crossing the upper bound number
- while (startingNumber < upperBound)
- {
- // after printing every number in loop, counting by 1
- System.out.print((startingNumber += stepSize) + " ");
- count++;
- // if the count value is a multiple of 10, print empty line
- // good habit here to use brackets for if statement in case of future modification
- if ((count%10) == 0) {
- System.out.println();
- }
- input.close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement