Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner; // program uses class Scanner
- public class TesterClass
- {
- // main method begins program execution
- public static void main( String[] args)
- {
- Scanner input = new Scanner ( System.in ); //declare new Scanner - input
- int total; // sum of all values entered by user
- int value = 0; // value entered by user
- value = input.nextInt(); // input next value
- total = 0; // initialize total
- while ( value != -1 ) // loop ends when -1 is inputted
- {
- System.out.print( "Enter an integer or -1 to quit:\n"); // prompt
- {
- // analyzes integer and compares
- if (value == total)
- System.out.printf("%d is the same as %d\n", value, total);
- value = input.nextInt(); // input next value
- if (value < total)
- System.out.printf("%d is less than %d", value, total);
- if (value > total)
- System.out.printf("%d is more than %d", value, total);
- total = total + value; // sums numbers
- } // end if
- } // end while
- // displays sum of values
- System.out.printf( "The final sum is %d/n", total );
- } // end method
- } // end class TesterClass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement