131k views
2 votes
Write a while loop that adjusts userValue while userValue is less than 0 or greater than 80. If userValue is greater than 80, then subtract 5 from userValue. If userValue is less than 0, then add 10 to userValue. 5 from userValue.

User Bardo
by
5.5k points

1 Answer

4 votes

Answer:

import java.util.Scanner;

public class num5 {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.println("Enter a value");

int userValue = in.nextInt();

//The While Loop

while(userValue<0||userValue>80){

if(userValue>80){

userValue=userValue-5;

}

else if(userValue<0){

userValue=userValue+10;

}

}

System.out.println("New UserValue is: "+userValue);

}

}

Step-by-step explanation:

  • This is solved using Java programming language
  • Use the scanner class to receive the userValue
  • Create a while loop with the condition as given in the question : userValue is less than 0 or greater than 80.
  • Within the while loop use if and else if statement to subtract 5 from the userValue if it is greater than 80 or add 10 to userValue if it is less than 0
User Jens Tinfors
by
5.5k points