Computer Science, asked by leenaratha, 9 months ago

Write a Java program to enter a string and word first letter is capital and last letter is small.​

Answers

Answered by hoangmustang
0

Answer:

This is my solution, check it out!

package newPack;

import java.util.*;

public class capitalFirst {

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

 String s = input.nextLine();//read the input from the user

 String [] a = s.split(" ");//split each word by space into String array

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

  for(int j = 0; j < a[i].length(); j++) {

   if(j==0)//the first character of a word

    System.out.print(Character.toUpperCase(a[i].charAt(j)));

   else//the last and another characters

    System.out.print(Character.toLowerCase(a[i].charAt(j)));

  }

  System.out.print(" ");//because it is splited by space, space will be deleted so we need to add space

 }

}

}

Explanation:

Similar questions