-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.java
More file actions
46 lines (26 loc) · 935 Bytes
/
Copy pathstring.java
File metadata and controls
46 lines (26 loc) · 935 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
String():The split() function is available in String Class. It use to split the string into substrings from given character.This function return the array of string.
String name="Sundram Singh";
String []shortname=name.split('');
charAt():-The charAt() function is used to access the character of given String of specified position.
*/
//Wap aprogram to take user name as i/p and display the short name.
import java.util.*;
class string
{
static public void main(String... args)
{
String name;
int i;
Scanner sc=new Scanner(System.in);
System.out.print("Enter your full name: ");
name=sc.nextLine();
String [] shortname=name.split(" ");
System.out.print("Your Short Name: ");
for(i=0;i<shortname.length-1;i++)
{
System.out.print(shortname[i].charAt(0)+".");
}
System.out.print(shortname[shortname.length-1]);
}
}