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
Illusion [34]
2 years ago
11

Write a program with a function that accepts a string as an argument and returns a copy of the string with the first character o

f each sentence capitalized. The program should let the user enter a string and then pass it to the function, printing out the modified string.
Computers and Technology
1 answer:
soldi70 [24.7K]2 years ago
3 0

Answer:

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

 System.out.println("Enter String");

 Scanner sc1=new Scanner(System.in);

 String st1=sc1.nextLine();

 convertfirstchartoupper(st1);

 //System.out.println(st1);

 

}

private static void convertfirstchartoupper(String st1){

     

      char[] arr = st1.toCharArray();

      int k =0;

      arr[0]=Character.toUpperCase(arr[0]);

      while(k<arr.length)

      {

         

         if(Character.isWhitespace(arr[k]))

         {

             

             arr[k+1]=Character.toUpperCase(arr[k+1]);

             

         }

         

         

        k++;

      }

      k=0;

       while(k<arr.length)

      {

         

        System.out.print(arr[k]);

         

        k++;

      }

  }

}

Explanation:

In the above java program, we change a string into an array of characters and then check for whitespace. the letter next to while space is the first letter of the new word, and hence we capitalize that letter. And this is what is required. However, we can split the sentence into a string of words as well, and then capitalize the first letter of each word.

You might be interested in
Write a program that prompts the user to enter the number of integer numbers you need to enter, then ask user to enter these int
nadya68 [22]

Answer:

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

 Scanner ob = new Scanner(System.in);

 System.out.println("How many numbers? ");

 int n = ob.nextInt();

       int[] arr = new int[n];  

 for (int i=0; i<n; i++) {

     System.out.print("Enter the number: ");

     arr[i] = ob.nextInt();

 }

    System.out.println(indexOfLargestElement(arr));

}

public static int indexOfLargestElement(int[] arr) {

    int max = arr[0];

    int maxIndex = 0;

    for (int i=0; i<arr.length; i++) {

        if (arr[i] >= max) {

            max = arr[i];

            maxIndex = i;

        }

    }

    return maxIndex;

}

}

Explanation:

Create a method called indexOfLargestElement that takes one parameter, an array

Initialize the max and maxIndex

Create a for loop iterates throgh the array

Check each element and find the maximum and its index

Return the index

Inside the main:

Ask the user to enter how many numbers they want to put in array

Get the numbers using a for loop and put them inside the array

Call the indexOfLargestElement method to find the index of the largest element in the array

8 0
3 years ago
Select the correct answer. Which input device uses optical technology?
daser333 [38]

Answer:

barcode reader is the correct answer

8 0
2 years ago
Mary needs to choose the menu in order to place the text in a desired fashion around the image.
n200080 [17]
Can you be more specific?

7 0
3 years ago
Read 2 more answers
In the legend of sleeping Hallow what does Ichabod Crane fear the most
ahrayia [7]

Ichabod Crane is terrified of the headless horsemen

3 0
3 years ago
Read 2 more answers
Which statement compares the copy and cut commands?
ella [17]

Answer: duplicate

Explanation:

5 0
2 years ago
Read 2 more answers
Other questions:
  • Compare and contrast the TwoFish encryption algorithm with the DES and AES algorithms. In your comparison be sure to compare and
    6·1 answer
  • Which activity constitutes legal computer activity?
    12·1 answer
  • Claim: Raising the minimum wage does not help most minimum wage employees Reason: Many small businesses cannot afford high minim
    14·2 answers
  • The cost of large ground based telescopes has remained the same since the 1800's costing the equivalent of about a billion dolla
    9·1 answer
  • Hiiiiiiiiiii hiiiiiiiiiiiiiiiiiii
    9·2 answers
  • Which of the following is a computerized job classification system that contains continually updated information regarding the k
    15·1 answer
  • Alexa it is olewi.............................................
    15·2 answers
  • Please help with question
    14·1 answer
  • How to get someone off your best friends list without blocking them
    8·1 answer
  • Which two features offered by SharePoint
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!