//How to enter the string and print first character in java
import java.util.*;
public class M
{
public static void main(String args[])
{
String s;
char c;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the character: ");
s=sc.next();
c=s.charAt(0);
System.out.println("First character of word is: "+c);
}
}
OUTPUT:
Enter the character:
Example
First character of word is: E
import java.util.*;
public class M
{
public static void main(String args[])
{
String s;
char c;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the character: ");
s=sc.next();
c=s.charAt(0);
System.out.println("First character of word is: "+c);
}
}
OUTPUT:
Enter the character:
Example
First character of word is: E
No comments:
Post a Comment