I’m new to Java programming and I need help.
Create a table of String and the user gives the size. Subsequently, the user gives String. I want to print the characters but without the characters which are not letters of the alphabet (eg. java!4 –> java, ja/?,.va –> java)
public static void main (String[] args) {
String[] x = new String[size];
int size;
String str= "";
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Give me size: ");
size = Integer.parseInt(input.readLine());
for(int i=0; i<size; i++){
System.out.print("Give me a String: ");
str = input.readLine();
x[i]=str;
}
}
I am looking on the internet for this code:
if (str.matches("[a-zA-Z]")){
System.out.println(str);
}
Since you’re new to programming and don’t want to involve in the RegEx world (yet), you can create a method that returns a
Stringwith letters only: