Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialnazim khan
1,409 PointsIm not getting the Expected result for my code
Hi I tried craig's code in Eclipse since workspace was not working Even if i enter 5 digit zip if condition is not satisfying... Need help to correct the code
import java.io.Console;
//import java .util.Scanner;
import java.util.*;
public class Expression {
public static void main(String[] args) {
// TODO Auto-generated method stub
//Console console=System.console();
Scanner scanner=new Scanner(System.in);
String zipcode=scanner.next();
//System.out.println("Enter the zip cod\n");
if(zipcode.matches("//d{5}")){
System.out.printf("%s is a valid zipcode %n",zipcode);
}
else {
System.out.printf("%s is not a valid zipcode %n",zipcode);
System.out.println("Enter the prorper code");
}
}
}
1 Answer
Craig Dennis
Treehouse TeacherYou accidentally are using forward slashes in your Regular Expression. You should use back slashes.
Hope it helps!