Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

/*Write a program in Java to accept a name containing three words and display the surname

first, followed by the first and middle names.


Sample Input: Mahendra Singh Dhoni
Sample Output: Dhoni Mahendra Singh
*/
import java.util.Scanner;

public class SurnameFirst


{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.println("Enter a name of 3 words:");
String name = in.nextLine();
int x= name.indexOf(' ');
int y= name.lastIndexOf(' ');
String first=name.substring(0,x);
String middle=name.substring(x+1,y);
String last=name.substring(y);

System.out.println(last+" "+first+" "+middle);


}
}
/* Write aprogram in java to input string in mixed case .find and display frequency of each
vowel
* frequency of each vowel*/
import java.util.*;
public class Frequency_eachvowel
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
System.out.println("enter the string ");
String str=s.nextLine();
char ch;
int a=0,e=0,i=0,o=0,u=0;
for(int j=0;j<str.length();j++)
{
ch=str.charAt(j);

if(ch=='A' || ch=='a')
a++;
else if(ch=='E' || ch=='e')
e++;
else if(ch=='I' || ch=='i')
i++;
else if(ch=='O' || ch=='o')//1
o++;
else if(ch=='U' || ch=='u')
u++;

}
System.out.println("frequency of a is"+a);
System.out.println("frequency of e is"+e);
System.out.println("frequency of i is"+i);
System.out.println("frequency of o is"+o);
System.out.println("frequency of u is"+u);
}
}

You might also like