162k views
2 votes
Write an if-else statement that displays 'Speed is normal' if the speed variable is within the range of 24 to 56. If the speed variable’s value is outside this range, display 'Speed is abnormal'.

1 Answer

3 votes

Answer:

import java.util.Scanner;

public class Speed{

int speed;

public Speed(int speed){

this.speed = speed;

}

public void checkSpeed(){

if(speed >= 24 || speed <= 56){

System.out.println("Speed is normal");

}

else

System.out.println("Speed is abnormal");

}

public static void main(String...args){

Scanner input = new Scanner(System.in);

int userSpeed = 0;

System.out.println("Enter a speed: ");

userSpeed = input.nextInt();

Speed obj1 = new Speed(userSpeed)

obj1.checkSpeed();

}

Step-by-step explanation:

User Justin Doyle
by
4.6k points