In: Computer Science
JAVA Input a phrase from the keyboard, if the phrase contains "red" or "RED" print out "red" . if the phrase contains "blue" or "BLUE" output "blue" In all other cases print "No Color" For example: If the input was "Violets are BLUE" your output should be "blue" If the input was "Singing the blues" output "blue" If the input was "I have a pure bred puppy" your output should be "red" If the input was "Today is Monday" output "No color". If the input was "My shirt is Blue" output "No color". (because you are only looking for "blue", "BLUE", "red", "RED")
Here Iam provding the code and the output for the given problem
Code for Main.java
Sample Outputs
Code for Main.java
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter your phrase
: ");
String phrase =
sc.nextLine();
if(phrase.contains("blue") ||
phrase.contains("BLUE"))
System.out.println("blue");
else if(phrase.contains("red") ||
phrase.contains("RED"))
System.out.println("red");
else
System.out.println("No
color");
}
}
NOTE : If you got the output correct please give me a thumbs up.Let me know in the comments if you have any doubts