Write a piece of Java code that uses a while loop to repeatedly prompt the user to type a number until the user types a non-negative number, then square it.
- Example output:
Type a non-negative integer: -5
Invalid number, try again: -1
Invalid number, try again: 11
11 squared is 121
sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem i
sectetur adipiscingUnlock access to this and over
10,000 step-by-step explanations
Have an account? Log In
sectetur adipiscin