ok what am i doing wrong, my program has to output and evaluate a string,
heres 3 examples of how it is supposed to run,
eg.1 (no string entered)
"java Word
Usage: java Word <string>"
eg.2(string containing punctuation and numbers gives the output "The string must consist of letters!")
"java Word AAABB@I5P
The string must consist of letters!"
eg.3(continous character gives the output)
"java Word AAAAAAAwwwwwwwwwwwTTT
7A11w3T"
and heres the code i got so far
import java.util.Scanner;
import java.io.PrintStream;
public class Word
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
PrintStream output = System.out;
output.print("java Word ");
String s = input.nextLine();
if (s.equals(""))
{
output.print("Usage: java Word <string>");
}
if (s.matches("[^0-9]*[0-9]+[^0-9]*"))
{
output.print("The string must consist of letters!");
}
if (s.matches("[\\p]")) //is this the correct code for all punctuations??
{
output.print("The string must consist of letters!");
}
}
}
when i enter a number i get the correct output, however I am not sure on how to exclude punctuations from the string and i get a weird error when typing in [\\p]
heres 3 examples of how it is supposed to run,
eg.1 (no string entered)
"java Word
Usage: java Word <string>"
eg.2(string containing punctuation and numbers gives the output "The string must consist of letters!")
"java Word AAABB@I5P
The string must consist of letters!"
eg.3(continous character gives the output)
"java Word AAAAAAAwwwwwwwwwwwTTT
7A11w3T"
and heres the code i got so far
import java.util.Scanner;
import java.io.PrintStream;
public class Word
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
PrintStream output = System.out;
output.print("java Word ");
String s = input.nextLine();
if (s.equals(""))
{
output.print("Usage: java Word <string>");
}
if (s.matches("[^0-9]*[0-9]+[^0-9]*"))
{
output.print("The string must consist of letters!");
}
if (s.matches("[\\p]")) //is this the correct code for all punctuations??
{
output.print("The string must consist of letters!");
}
}
}
when i enter a number i get the correct output, however I am not sure on how to exclude punctuations from the string and i get a weird error when typing in [\\p]