15. Write a loop that will count the number of blank characters in a given string.
import javax.swing.JOptionPane;
public class BlankChar {
public static void main(String[] args) {
String str;
int a=0;
str=JOptionPane.showInputDialog("Enter String: ");
str=str.toLowerCase();
for(int x=0;x<=str.length()-1;x++){
if(str.charAt(x)==' '){
a++;
}
else{
}
}
JOptionPane.showMessageDialog(null, "The number of blank characters in the given string is: "+a);
}
}
Walang komento:
Mag-post ng isang Komento