Advertisement
Guest User

Untitled

a guest
Oct 5th, 2015
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. import java.util.Scanner; // program uses class Scanner
  2.  
  3. public class TesterClass
  4. {
  5. // main method begins program execution
  6. public static void main( String[] args)
  7. {
  8. Scanner input = new Scanner ( System.in ); //declare new Scanner - input
  9.  
  10. int total; // sum of all values entered by user
  11. int value = 0; // value entered by user
  12.  
  13. value = input.nextInt(); // input next value
  14. total = 0; // initialize total
  15.  
  16. while ( value != -1 ) // loop ends when -1 is inputted
  17. {
  18. System.out.print( "Enter an integer or -1 to quit:\n"); // prompt
  19. {
  20. // analyzes integer and compares
  21. if (value == total)
  22. System.out.printf("%d is the same as %d\n", value, total);
  23. value = input.nextInt(); // input next value
  24. if (value < total)
  25. System.out.printf("%d is less than %d", value, total);
  26. if (value > total)
  27. System.out.printf("%d is more than %d", value, total);
  28. total = total + value; // sums numbers
  29. } // end if
  30.  
  31. } // end while
  32. // displays sum of values
  33. System.out.printf( "The final sum is %d/n", total );
  34. } // end method
  35. } // end class TesterClass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement