+ 1
How to find vowel "i" in the string which is inputed by user ?
7 odpowiedzi
+ 2
http://code.sololearn.com/cq0a4WEE0KuA
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Please enter a word: ");
String s = sc.nextLine();
System.out.println(s);
int i;
for(i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'i') {
break;
}
}
if (i != s.length()) {
System.out.println("i found at index " + i);
} else {
System.out.println("i not found");
}
}
}
+ 2
You could use indexOf to get the sum od i's
see below
http://code.sololearn.com/ceIHXOdCdlhx/#java
public class Main {
public static void main(String[] args) {
String word = "His ice-cream in his pocket";
int i = -1;
int sum = 0;
System.out.println();
while ((i=word.indexOf("i",i+1)) != -1) {
++sum;
}
System.out.println("number of i in '" + word+ "' is " + sum);
}
}
+ 1
break is to break out of the loop.
0
what function of "break"?
0
This method has following different variants:
public int indexOf(int ch): Returns the index within this string of the first occurrence of the specified character or -1 if the character does not occur.
public int indexOf(int ch, int fromIndex): Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index or -1 if the character does not occur.
int indexOf(String str): Returns the index within this string of the first occurrence of the specified substring. If it does not occur as a substring, -1 is returned.
int indexOf(String str, int fromIndex): Returns the index within this string of the first occurrence of the specified substring, starting at the specified index. If it does not occur, -1 is returned.
Syntax:
Here is the syntax of this method:
public int indexOf(int ch )
or
public int indexOf(int ch, int fromIndex)
or
int indexOf(String str)
or
int indexOf(String str, int fromIndex)
Parameters:
Here is the detail of parameters:
ch -- a character.
fromIndex -- the index to start the search from.
str -- a string.
source
http://www.tutorialspoint.com/java/java_string_indexof.htm
0
so how i sum of 'i' vowel in that string?
0
if any body know,how to find vowel in own name ,for ex,-which letter is vowel, Name-avinash raj here a,i is vowel