Write a program to calculate the total number of character(INCLUDE SPACES, EXCEPT VOWELS) in
a string entered by user.
Answers
Answered by
0
Answer:
Program:-
import java.util.*;
public class Demo
{
public static void main(String args[ ])
{
Scanner in=new Scanner(System.in);
int c=0,p;
String st;
char ch;
System.out.println("Enter a String");
st=in.nextLine();
p=st.length();
for(int i=0;i<p;i++)
{
ch=st.charAt(i);
if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U'||ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
{
continue;
}
else
c++;
}
System.out.println("The number of Characters and spaces="+c);
}
}
Refer to the attachment:-
- The first photo is the program.
- The second photo is the input.
- The third photo is the output.
Explanation of input:-
I love BLUEJ
- 1st space
- 2nd l
- 3rd v
- 4th space
- 5th B
- 6th L
- 7th J
Attachments:
Similar questions