the purpose of the code is to ask the user to input a string.
if there is an "a" in it - the place of it in the string will be shown. if not - there will be a line "no a in the string".
the problem is that i wrote the sentence "no a in the string" in the loop, and therefore it appears a few times and not only once....
how can i write it out of the loop? put the loop in another condition?
here's the code:
import java.util.Scanner;
public class Tirgul {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println ("enter a string");
String str = s.nextLine();
int i = str.length();
int b;
for (b=0; i > b;++b) {
if (str.charAt(b) == 'a')
System.out.println ("a is in the " + (b+1) + " place");
else
System.out.println ("no a in the string");
}
}
}