Ask Question
28 December, 03:07

Assume that nextWord is a String variable that has been given a String value consisting entirely of letters. Write some Java code that outputs the message "First half of the alphabet", provided nextWord precedes "N" in alphabetic ordering. IfnextWord does not precede "N" in alphabetic ordering, the code should output"Second half of the alphabet". (Note that "N"uses double quotes to produce aString value, as opposed to using single quotes to produce achar value.) '

+4
Answers (1)
  1. 28 December, 04:31
    0
    The code example is given below with explanation in c+ + language.

    Explanation:

    Comments will explain what's going on in the code. Below code is already compiled and tested.

    #include

    #include

    #include

    using namespace std;

    int main (void)

    {

    //defining start and end time variable

    / / which will be used to break the infinte loop

    time_t endwait;

    time_t start = time (NULL);

    time_t seconds = 3; / / end loop after this time has elapsed

    cout<<"Input your number : ";

    long userNum;

    cin>> userNum;

    / / initializing end time by adding seconds with start time

    endwait = start + seconds;

    / / defining outputString which will concatenate all the

    / / divisible numbers in loop

    string outputString="";

    / / bool isCompleted will use to check whether our

    / / loop breaks successfully or time is expired.

    bool isCompleted=true;

    / / iterate loop until it comes to 1. as in loop

    / / the program already displayed the 1 value.

    while (userNum>1)

    {

    / / checking start and end time comparison to

    / / break the infinite loop after some seconds

    if (start > = endwait) {

    cout<< "Program end never reached.";

    isCompleted=false;

    break;

    }

    userNum=userNum/2;

    / / defining stringstream to convert from long to string

    stringstream longToString;

    longToString<
    / / concatenating all the values

    outputString = outputString + longToString. str () + " ";

    / / re initializing the start time with current time.

    start = time (NULL);

    }

    / / check if while loop breaks successfully then print the

    / / series of numbers here.

    if (isCompleted) {

    cout << outputString;

    }

    return 0;

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Assume that nextWord is a String variable that has been given a String value consisting entirely of letters. Write some Java code that ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers