Question

In: Computer Science

CHALLENGE ACTIVITY 3.12.1: String comparison: Detect word. Write an if-else statement that prints "Goodbye" if userString...

CHALLENGE

ACTIVITY

3.12.1: String comparison: Detect word.

Write an if-else statement that prints "Goodbye" if userString is "Quit", else prints "Hello". End with newline.

import java.util.Scanner;

public class DetectWord {
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
String userString;

userString = scnr.next();

/* Your solution goes here */

}
}

Solutions

Expert Solution

import java.util.Scanner;

public class DetectWord

{

    public static void main (String [] args)

    {

        Scanner scnr = new Scanner(System.in);

        String userString;

        userString = scnr.next();

        if (userString.equals("Quit") )

        {

           System.out.println("Goodbye");

        }

        else

        {

            System.out.println("Hello");

        }

    }

}


Related Solutions

Write a Python loop that goes through the list and prints each string where the string...
Write a Python loop that goes through the list and prints each string where the string length is three or more and the first and last characters of the strings are the same. Test your code on the following three versions of the list examples: examples = ['abab', 'xyz', 'aa', 'x', 'bcb'] examples = ['', 'x', 'xy', 'xyx', 'xx'] examples = ['aaa', 'be', 'abc', 'hello'].
Write a Java program that takes in a string and a number and prints back the...
Write a Java program that takes in a string and a number and prints back the string from the number repeatedly until the first character... for example Pasadena and 4 will print PasaPasPaP. Ask the user for the string and a number Print back the string from the number repeatedly until the first character For both programs please utilize: methods arrays loops Turn in screenshots
Word to Digit Programming challenge description: Given a string representation of a set of numbers, print...
Word to Digit Programming challenge description: Given a string representation of a set of numbers, print the digit representation of the numbers. Input: Your program should read lines from standard input. Each line contains a list of word representations of numbers separated by a semicolon. There are up to 20 numbers in one line. The numbers are "zero" through "nine". Output: Print the sequence of digits. Test 1 Input zero;two;five;seven;eight;four Expected Test 1 output 025784 Test 2 Input three;seven;eight;nine;two Expected...
Write a Java program that prompts the user to input a string and prints whether it...
Write a Java program that prompts the user to input a string and prints whether it is a palindrome. A palindrome is a string which reads the same backward as forward, such as Madam (disregarding punctuation and the distinction between uppercase and lowercase letters). The program must use the stack data structure. The program must include the following classes: The StackX class (or you can use the Java Stack class). The Palindrome class which must contain a method named palindrome()...
In Java, write a recursive function that accepts a string as its argument and prints the...
In Java, write a recursive function that accepts a string as its argument and prints the string in reverse order. Demonstrate the function in a driver program.
Assume s is a string of numbers. Write a program that prints the longest substring of...
Assume s is a string of numbers. Write a program that prints the longest substring of s in which the numbers occur in ascending order and compute the average of the numbers found. For example, if s = '561984235272145785310', then your program should print Longest substring in numeric ascending order is: 14578 Average: 5 In the case of ties, print the first substring. For example, if s = '147279', then your program should print Longest substring in numeric ascending order...
Write a class to accept a sentence from the user and prints a new word in...
Write a class to accept a sentence from the user and prints a new word in a terminal formed out of the third letter of each word. For example, the input line “Mangoes are delivered after midnight” would produce “neltd”. Program Style : Basic Java Programming
1. The "else" clause is required for a decision statement. 2. A String variable can be...
1. The "else" clause is required for a decision statement. 2. A String variable can be assigned to an integer variable. 3. An integer variable can be assigned to a boolean variable. 4. We can calculate the square root of numbers with the class java.util.Math. 5. String is a Java primitive data type. 6. A ‘Double’ object can be assigned to a ‘String’ data variable. 7. Every Java class has to have a static main() method to avoid compilation error....
Python Assume s is a string of numbers. Write a program that prints the longest substring...
Python Assume s is a string of numbers. Write a program that prints the longest substring of s in which the numbers occur in ascending order and compute the average of the numbers found. For example, if s = '561984235272145785310', then your program should print: Longest substring in numeric ascending order is: 14578 Average: 5 In the case of ties, print the first substring. For example, if s = '147279', then your program should print Longest substring in numeric ascending...
Text Wrap Problem Write a program in Python that takes an input string and prints it...
Text Wrap Problem Write a program in Python that takes an input string and prints it as multiple lines of text such that no line of text is greater than 13 characters and words are kept whole. For example, the first line of the Gettysburg address: Four score and seven years ago our fathers brought forth upon this continent a new nation, conceived in liberty and dedicated to the proposition that all men are created equal Becomes: Four score and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT