Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added my Day 4 Java code #360

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions day4/Java/VowelsInAString.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* @date 13/10/2020
* @author Shashwat Gupta (shashwatxdevelop)
*/
import java.util.Scanner;
public class VowelsInAString {

public static void main(String[] args) {
String s; int k = 0, l, i; char ch = 0;
Scanner sc = new Scanner (System.in);
System.out.println("Enter the string");
s = sc.nextLine(); //taking input as string
l = s.length(); //finding length of the string
for (i=0; i<l; i++)
{
ch= s.charAt(i); //extracting the character from the string
if(ch=='a' || ch == 'A' || ch == 'e' || ch=='E' || ch=='i' || ch=='I' || ch=='o' || ch== 'O'|| ch=='u' || ch=='U')
{
k++; //increasing the counter variable by 1 if vowel is found
}

}
System.out.println("Number of vowels in the string is " + k); //printing the total number of vowels in the string
}

}
27 changes: 26 additions & 1 deletion day4/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -888,9 +888,34 @@ str = gets
str.chomp!
puts "The most frequent character in #{str} is : #{most_frequent_character(str)}"
```
/* @date 13/10/2020
* @author Shashwat Gupta (shashwatxdevelop)
*/
import java.util.Scanner;
public class VowelsInAString {

public static void main(String[] args) {
String s; int k = 0, l, i; char ch = 0;
Scanner sc = new Scanner (System.in);
System.out.println("Enter the string");
s = sc.nextLine(); //taking input as string
l = s.length(); //finding length of the string
for (i=0; i<l; i++)
{
ch= s.charAt(i); //extracting the character from the string
if(ch=='a' || ch == 'A' || ch == 'e' || ch=='E' || ch=='i' || ch=='I' || ch=='o' || ch== 'O'|| ch=='u' || ch=='U')
{
k++; //increasing the counter variable by 1 if vowel is found
}

}
System.out.println("Number of vowels in the string is " + k); //printing the total number of vowels in the string
}

}
```
### Have Another solution?

The beauty of programming lies in the fact that there is never a single solution to any problem.

In case you have an alternative way to solve this problem, do contribute to this repository (https://github.com/CodeToExpress/dailycodebase) :)
In case you have an alternative way to solve this problem, do contribute to this repository (https://github.com/CodeToExpress/dailycodebase) :)