Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Problem2 {
- public static void main(String args[]) {
- // create variables
- int numberOfBigSteps = 0;
- int numberOfSmallSteps = 0;
- int currentEntry = 0;
- int previousEntry = 0;
- Scanner scan = new Scanner(System.in);
- while (currentEntry > 0) {
- // loop user input until the user enters a number that is either
- // a) less than or equal to 0
- // b) less than the previous number
- // currently it is not working at all and I can't enter any numbers
- System.out.print("Enter a positive integer: ");
- currentEntry = scan.nextInt();
- if (currentEntry <= 0 || currentEntry <= previousEntry) {
- if ((currentEntry - previousEntry) > 5)
- // difference of more than 5
- numberOfBigSteps++;
- }
- if ((currentEntry - previousEntry) <= 5) {
- numberOfSmallSteps++;
- if (currentEntry == previousEntry) {
- numberOfSmallSteps++;
- }
- }
- // output
- System.out.println("Big steps: " + numberOfBigSteps);
- System.out.println("Small steps: " + numberOfSmallSteps);
- System.out.println("Ending value: " + currentEntry);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement