Question

WRITE THIS IN JAVA!!!!

Print Censored if userlnput contains the word darn, else print userlnput. End with newline. Ex: If userlnput is That dar

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;
public class Main{
public static void main(String args[]) {
Scanner scnr=new Scanner(System.in);
String userInput;
System.out.println("Enter String: ");
userInput=scnr.nextLine();
int res=userInput.indexOf("darn");
if(res == - 1) {
System.out.println(userInput);
} else {
System.out.println("Censored");
}
}
}input Enter String: that darn cat Censored . Program finished with exit code 0 Press ENTER to exit console. al

Add a comment
Know the answer?
Add Answer to:
WRITE THIS IN JAVA!!!! Print "Censored" if userlnput contains the word "darn", else print userlnput. End...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Print 'Censored if userinput contains the word"darn', else print userinput End with newline. Ex iIf userinput...

    Print 'Censored if userinput contains the word"darn', else print userinput End with newline. Ex: if userinput is "That darn cat.:. then output is: Censored Ex: If userinput is Dang, that was scaryl", then output is: Dang, that was scary Note: If the submitted code has an out-of-range access, the system will stop running the code after a few seconds, and report Program end never reached The system doesn't print the test case that caused the reported message. import java.util.Scanner; public class Censoredwords {public static...

  • Unreachable statement??????? CSIT 111 home> 313: More string operations E zyBooks catalog Print 'Censored if userinput...

    Unreachable statement??????? CSIT 111 home> 313: More string operations E zyBooks catalog Print 'Censored if userinput contains the word 'darn, else print userinput. End with newline Note: These activities may test code with different test values. This activity will perform three tests, with userinput of That darn cat', then with Dang, that was scary!", then with I'm darning your socks.. See How to Use zyBooks . Also note: If the submitted code has an out-of-range access, the system will stop...

  • in java Feedback? CHALLENGE ACTIVITY 5.2.2: Printing array elements. Write three statements to print the first...

    in java Feedback? CHALLENGE ACTIVITY 5.2.2: Printing array elements. Write three statements to print the first three elements of array run Times. Follow each statement with a newline. Ex: If runTime = (800,775, 790, 805, 808) print: 800 775 790 Note: These activities will test the code with different test values. This activity will perform two tests, both with a 5 element array. See 'How to Use zyBooks". Also note: If the submitted code tries to access an invalid array...

  • Write three statements to print the first three elements of array runTimes. Follow each statement with...

    Write three statements to print the first three elements of array runTimes. Follow each statement with a newline. Ex: If runTime = {800, 775, 790, 805, 808}, print: 800 775 790 Note: These activities will test the code with different test values. This activity will perform two tests, both with a 5-element array. See "How to Use zyBooks". Also note: If the submitted code tries to access an invalid array element, such as runTimes[9] for a 5-element array, the test...

  • 7.2.3: Printing array elements with a for loop. Write a for loop to print all elements...

    7.2.3: Printing array elements with a for loop. Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, then backwards. End each loop with a newline. Ex: If courseGrades = {7, 9, 11, 10}, print: 7 9 11 10 10 11 9 7 Hint: Use two for loops. Second loop starts with i = courseGrades.length - 1. (Notes) Also note: If the submitted code tries to access an invalid...

  • Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Follow...

    Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Follow each number by a space. Example output for userNum = 40: 20 10 5 2 1 Note: These activities may test code with different test values. This activity will perform four tests, with userNum = 40, then with userNum = 2, then with userNum = 0, then with userNum = -1. See "How to Use zyBooks". Also note: If the submitted code has an...

  • In JAVA ACTIVITY 3.10.1: Rock-paper-scissors. Write a switch statement that checks nextChoice. If o print "Rock"....

    In JAVA ACTIVITY 3.10.1: Rock-paper-scissors. Write a switch statement that checks nextChoice. If o print "Rock". If 1 print "Paper". If 2 print "Scissors'. For any other value, print "Unknown'. End with newline. 2. 4 1 import java.util.Scanner; 3 public class Roshambo public static void main(String [] args) { 5 Scanner scnr - new Scanner(System.in); 6 int nextChoice; 7 8 nextChoice - scnr.nextInt(); 9 10 /" Your solution goes here */ 11 12 13} CHALLENGE ACTIVITY 3.10.2: Switch statement to...

  • Write a do-while loop that continues to prompt a user to enter a number less than...

    Write a do-while loop that continues to prompt a user to enter a number less than 100, until the entered number is actually less than 100. End each prompt with newline Ex: For the user input 123, 395, 25, the expected output is: Enter a number (<100): Enter a number (<100): Enter a number (<100): Your number < 100 is: 25 import java.util.Scanner; public class NumberPrompt { public static void main (String [] args) { Scanner scnr = new Scanner(System.in);...

  • Answer in JAVA 1. Complete the method definition to output the hours given minutes. Output for...

    Answer in JAVA 1. Complete the method definition to output the hours given minutes. Output for sample program: 3.5 import java.util.Scanner; public class HourToMinConv {    public static void outputMinutesAsHours(double origMinutes) {       /* Your solution goes here */    }    public static void main (String [] args) {       Scanner scnr = new Scanner(System.in);       double minutes;       minutes = scnr.nextDouble();       outputMinutesAsHours(minutes); // Will be run with 210.0, 3600.0, and 0.0.       System.out.println("");    } } 2....

  • Write an expression that executes the loop while the user enters a number greater than or...

    Write an expression that executes the loop while the user enters a number greater than or equal to 0. Note: These activities may test code with different test values. This activity will perform three tests, with user input of 9, 5, 2, -1, then with user input of 0, -17, then with user input of 0 1 0 -1. Also note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT