answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Burka
3 months ago
11

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

Computers and Technology
2 answers:
Natasha_Volkova [1K]3 months ago
5 0

For Java, the if statement would be:

if(userSting.equals("Quit")) {

    System.out.println("Goodbye");

}

else {

    System.out.println("Hello");

}

The if condition tests whether the user input matches "Quit." If it does, the program prints "Goodbye." Otherwise, for any other input, the else block runs, outputting "Hello."

oksian1 [950]3 months ago
4 0

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

}

  }

}

This code functions correctly for any input and yields the expected behavior according to zybooks requirements

You might be interested in
Java languageThe cost to ship a package is a flat fee of 75 cents plus 25 cents per pound.1. Declare a constant named CENTS_PER_
oksian1 [950]
// Below is Java code. // Package import import java.util.*; // class definition class Main { // class main method public static void main (String[] args) throws java.lang.Exception { try{ // variables final int CENTS_PER_POUND = 25; final int FLAT_FEE_CENTS = 75; // Creating Scanner object for input Scanner sr=new Scanner(System.in); System.out.print("Enter the shipping weight:"); // input reading int shipWeightPounds=sr.nextInt(); // cost calculation int shipCostCents = (shipWeightPounds * CENTS_PER_POUND) + FLAT_FEE_CENTS; // output Weight System.out.println("shipping Weight: " + shipWeightPounds); // output flat fee System.out.println("flat fee of shipping in cents: " + FLAT_FEE_CENTS); // output cents per pound System.out.println("Cents/pound for shipping: " + CENTS_PER_POUND); // output shipping cost System.out.println("total cost of shipping in cents: " + shipCostCents); catch(Exception ex){ return;} } } // Explanation: Define two constants "CENTS_PER_POUND=25" and "FLAT_FEE_CENTS=75". Use a Scanner object to capture user input for weight. Calculate the shipping cost by multiplying the weight with cents per pound and adding the flat fee. Then, display each value.
8 0
2 months ago
Read 2 more answers
In the lab, you used the filter box in Wireshark to remove traffic from port 3389. What is that port used for? What filter synta
8_murik_8 [964]

Answer:

Port 3389 is designated for remote desktop access to graphical user interfaces.

The syntax for tracking ping traffic is " tcp.port eq 25 or icmp".

Explanation:

Wireshark serves as a network packet sniffer utilized for analyzing and troubleshooting packet transmission within a network.

The ping command is employed in networks to verify connectivity between two devices. It sends ICMP echo messages to an IP address and awaits their return if the connection exists. To filter ping traffic in Wireshark, the syntax " tcp.port eq 25 or icmp" is applied.

This port 3389 acts as a listening port for the Microsoft proprietary remote desktop protocol, allowing remote connections to graphical interfaces of systems running the RDP server.

6 0
2 months ago
A method countDigits(int num) of class Digits returns the remainder when the input argument num(num > 0) is divided by the nu
ivann1987 [1066]

Answer:

#include <iostream>

using namespace std;

class Digits

{

   public:

   int num;

   int read()       //method to read num from user

   {

       cout<<"Enter number(>0)\n";

       cin>>num;

       return num;

   }

   int digit_count(int num)  //method to count number of digits of num

   {

       int count=0;

       while(num>0)    //loop till num>0

       {

           num/=10;

           count++;   //counter which counts number of digits

       }

       return count;

   }

   int countDigits(int num)   //method to return remainder

   {

       int c=digit_count(num); //calls method inside method

       return num%c;  

   }

};

int main()

{

   Digits d;    //object of class Digits is created

   int number=d.read();   //num is read from user

   cout<<"\nRemainder is: "<<d.countDigits(number);  //used to find remainder

   return 0;

}

Output:

Enter number(>0)

343

Remainder is: 1

Explanation:

The program has a logical error that needs rectification. A correctly structured program calculates the remainder when a number is divided by the count of its digits. A class named Digits is created, consisting of the public variable 'num' and methods for reading input, counting digits, and calculating the remainder.

  • read() - This function asks the user to enter the value for 'num' and returns it.
  • digit_count() - This function accepts an integer and counts how many digits it has, incrementing a counter until 'num' is less than or equal to 0. It ultimately returns the digit count.
  • countDigits() - This function takes an integer and delivers the remainder from dividing that number by its digit count. The digit count is computed using the 'digit_count()' method.

Finally, in the main function, a Digits object is instantiated, and its methods are utilized to produce an output.

7 0
3 months ago
Would two bits be enough to assign a unique binary number to each vowel in the English language? Explain.
Harlamova29_29 [1022]

Response:

No.

Clarification:

Since there are 5 vowels, at least 3 bits are necessary to represent them all. Utilizing 2 bits yields 2²=4 combinations, which isn’t enough. However, using 3 bits provides 2³=8 combinations, sufficiently covering the 5 vowels.

3 0
3 months ago
Given num_rows and num_cols, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print
zubka84 [1067]

Answer:

The Python program is outlined below.

Explanation:

4 0
3 months ago
Other questions:
  • Which of the following is true? a. Pseudocode is used to describe an algorithm. b. Pseudocode is not an actual computer programm
    11·1 answer
  • In a survey of 7200 T.V. viewers, 40% said they watch network news programs. Find the margin of error for this survey if we want
    6·1 answer
  • What term best describes the grammatical rules for writing proper code? paths syntax hyperlinks declarations
    7·2 answers
  • The position of a runner in a race is a type of analog data. The runner’s position is tracked using sensors. Which of the follow
    8·1 answer
  • Which of the following statements are true about the growth of technology? Select 3 options. A. Individuals in the United States
    6·2 answers
  • Laura has identified the job she wants, the skills needed for the position, and the areas she needs to improve in order to get i
    15·1 answer
  • In QlikView, ________ are used to search information anywhere in the document.
    8·1 answer
  • A particular vendor uses the following approach to intrusion detection.16 The company maintains a large number of honeypots dist
    5·1 answer
  • Kylee needs to ensure that if a particular client sends her an email while she is on vacation, the email is forwarded to a
    10·1 answer
  • To reduce costs and the environmental impact of commuting, your company decides to close a number of offices and to provide supp
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!