1answer.
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
Ivahew [28]
3 years ago
10

Problem 1: you must write a method for this problem called sentenceAnalyzer Write a program that reads a sentence from the keybo

ard. Depending on the last character of the sentence, generate output identifying the sentence as declarative (ends with a period), interrogative (ends with a question mark), exclamatory (ends with an exclamation point), or unknown.
Computers and Technology
1 answer:
forsale [732]3 years ago
8 0

Answer:

   static void sentenceAnalyzer(String sentence){

       int lenOfString = sentence.length()-1;

   

           if(sentence.charAt(lenOfString)=='.'){

               System.out.println("Declarative");

             

           }

           else   if(sentence.charAt(lenOfString)=='?'){

               System.out.println("Interrogative");

             

           }

           else if(sentence.charAt(lenOfString)=='!'){

               System.out.println("Exclamation");

             

           }

           else{

               System.out.println("Unknown");

             

           }

   

   }

Explanation:

Using Java programming language

Create the method as required

Obtain the index of the last element using the string length method

Use if and else statements to check if the character at the last index is equal to any of the characters given and print the expected output

see a complete code with the main method below

<em>import java.util.Scanner;</em>

<em>public class num11 {</em>

<em>    public static void main(String[] args) {</em>

<em>        Scanner in = new Scanner(System.in);</em>

<em>        //Receiving User input</em>

<em>        System.out.println("Enter a sentence");</em>

<em>        String sentence = in.nextLine();</em>

<em>        // Calling the method</em>

<em>        sentenceAnalyzer(sentence);</em>

<em>    }</em>

<em>    static void sentenceAnalyzer(String sentence){</em>

<em>        int lenOfString = sentence.length()-1;</em>

<em />

<em>            if(sentence.charAt(lenOfString)=='.'){</em>

<em>                System.out.println("Declarative");</em>

<em>            }</em>

<em>            else   if(sentence.charAt(lenOfString)=='?'){</em>

<em>                System.out.println("Interrogative");</em>

<em>            }</em>

<em>            else if(sentence.charAt(lenOfString)=='!'){</em>

<em>                System.out.println("Exclamation");</em>

<em>            }</em>

<em>            else{</em>

<em>                System.out.println("Unknown");</em>

<em>            }</em>

<em>    }</em>

<em>}</em>

<em />

You might be interested in
Consider the following method, inCommon, which takes two Integer ArrayList parameters. The method returns true if the same integ
sp2606 [1]

Answer:

The answer is "Option b".

Explanation:

In the given code, a static method "inCommon" is declared, that accepts two array lists in its parameter, and inside the method two for loop is used, in which a conditional statement used, that checks element of array list a is equal to the element of array list b. If the condition is true it will return the value true, and if the condition is not true, it will return a false value. In this, the second loop is not used because j>0 so will never check the element of the first element.

6 0
3 years ago
Which tasks can Kim complete using the Customize Ribbon dialog box? Check all that apply.
exis [7]

Answer:

Its A, B, C, and F

Explanation:

On edg

5 0
2 years ago
a customer is looking for efficient alert management for its Data centre operations for reducing human effort in monitoring and
MAXImum [283]

Answer:Yes !

Explanation:  I totally agree, he really is looking !

8 0
2 years ago
Hooollaaaa , todos absolutamente todos quieren borrar esta tarea por que no tiene nada que ver con la materias del colegiooo per
Andreas93 [3]

Answer:

JAJAJSJJS XD PERO SI SOY

7 0
2 years ago
Read 2 more answers
A window frame will expand to fill the entire desktop when you
natima [27]
A. Sometimes it is marked by outwards pointing arrows (<= =>) with the reverse (collapsing so as to not take up the whole screen) being in the same spot, marked by inwards arrows (=> <=)
8 0
2 years ago
Other questions:
  • A factory has a dedicated room just for computers. They are generally kept locked in the room and are never directly used by use
    5·2 answers
  • Define the method object inc_num_kids() for personinfo. inc_num_kids increments the member data num_kids. sample output for the
    11·1 answer
  • When a defendant pleads guilty to one offense just to have another offense dropped, this is what type of plea bargain
    12·2 answers
  • Is instant messaging a form of synchronous communication
    10·1 answer
  • State whether true or false.
    6·1 answer
  • Over the past few years a very definite need has arisen in the electrical trades for:
    15·1 answer
  • How can you remove heat from a computer?
    10·1 answer
  • What was a result of george washington's belief in the sovereignty of the people instead of monarchy?
    9·1 answer
  • How to make a project using PID and thermacouple
    11·1 answer
  • Fill in the blanks
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!