Thursday, 19 November 2020

Program in Java to accept a String and Print its First and last Character

import java.util.*;

class string

{

public static void main(String args[])

{

Scanner in=new Scanner(System.in);

String s;

System.out.println("Enter a Sentence");

s=in.nextLine();

System.out.println("The First Letter: "+s.charAt(0));

System.out.println("The Last Letter: "+s.charAt(s.length()-2);

}

}

No comments:

Post a Comment

Java Program to count the total number of characters in a string

 //Java Program to count the total number of characters in a string import java.util.*; public class CountChars {     public static void mai...