Question

In: Computer Science

JAVA Input a phrase from the keyboard, if the phrase contains "red" or "RED" print out...

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")

Solutions

Expert Solution

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


Related Solutions

Input a phrase from the keyboard. If the last letter in the phrase is "a" or...
Input a phrase from the keyboard. If the last letter in the phrase is "a" or "e" (uppercase or lowercase) then output the last letter 3 times. ELSE If the first letter in the phrase is either "i", "o", or "u" (uppercase or lowercase) then output the length of the phrase In all other cases print "no vowel" Code language is java
Input a phrase from the keyboard and output whether or not it is a palindrome. For...
Input a phrase from the keyboard and output whether or not it is a palindrome. For example: 1. If the input is Madam I'm Adam Your output should be "Madam, I'm Adam" is a palindrome 2. If your input is Going to the movies? Your output should be "Going to the movies?" is not a palindrome Note the quotes in the output line. Code language java using JGrasp
Input a phrase from the keyboard. For example, input could be: Today is a rainy day,...
Input a phrase from the keyboard. For example, input could be: Today is a rainy day, but the sun is shining. Your program should count (and output) the number of "a"s in the phrase, the number of "e"s, the number of "i"s , the number of "o"s, the number of "u"s, and the total number of vowels. Note: The number of "a"s means the total of uppercase and lowercase "a"s etc. Also: the vowels are a,e,i,o,u. In the above example...
(C++) Write a program that reads a list of integers from the keyboard and print out...
(C++) Write a program that reads a list of integers from the keyboard and print out the smallest number entered. For example, if user enters 0 3 -2 5 8 1, it should print out -2. The reading stops when 999 is entered.
Write java program that will ask for the user for 2 input lines and print out...
Write java program that will ask for the user for 2 input lines and print out all words that occur 1 or more times on both lines (case sensitive). Write this without arrays and method. Here is a sample run: <Output> Enter two lines to process. The quick brown fox jumps over a lazy dog The fox hound outruns the lazy dog The words that occur on both lines are: The fox lazy dog
Write Java code that accepts the integer input (from keyboard) in an arraylist named num1 and...
Write Java code that accepts the integer input (from keyboard) in an arraylist named num1 and stores the even integers of num1 in another arraylist named evennum.
def main(): phrase = input('Enter a phrase: ') # take a phrase from user acronym =...
def main(): phrase = input('Enter a phrase: ') # take a phrase from user acronym = '' # initialize empty acronym for word in phrase.split(): # for each word in phrase acronym += word[0].upper() # add uppercase version of first letter to acronym print('Acronym for ' + phrase + ' is ' + acronym) # print results main() The program should then open the input file, treat whatever is on each line as a phrase and make its acronym using...
Java Program General Scenario: You are creating an interactive application that gets input from the keyboard...
Java Program General Scenario: You are creating an interactive application that gets input from the keyboard and keeps track of a grocery store that a businessman runs. In order to develop this application, you will be using 2 interfaces, 1 abstract class, and 1 concrete class. You should use the interfaces and the abstract class to create the concrete class. Your application should have overridden toString() at appropriate places so that you could display the object state, i.e., the string...
Write a program whose input is a string which contains a character and a phrase, and...
Write a program whose input is a string which contains a character and a phrase, and whose output indicates the number of times the character appears in the phrase. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: z Today is Monday the output is: 0 Ex: If the input is: n It's a sunny day the output is: 2 Case matters. Ex: If the input is: n Nobody the output is: 0...
Write a driver to get a String input from keyboard and if the input string has...
Write a driver to get a String input from keyboard and if the input string has less than 10 characters, throw a StringTooShortException. public class StringTooShortException extends Exception {     //-----------------------------------------------------------------     // Sets up the exception object with a particular message.     //-----------------------------------------------------------------     public StringTooShortException()     {         super("String does not have enough characters");     } }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT