Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3668120
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:05:03+00:00 2026-05-19T02:05:03+00:00

public static void main(String[] args) throws IOException { String str1 = ΔΞ123456; System.out.println(str1+-+str1.matches(^\\p{InGreek}{2}\\d{6})); //ΔΞ123456-true

  • 0
public static void main(String[] args) throws IOException {
   String str1 = "ΔΞ123456";
   System.out.println(str1+"-"+str1.matches("^\\p{InGreek}{2}\\d{6}")); //ΔΞ123456-true

   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
   String str2 = br.readLine(); //ΔΞ123456 same as str1.
   System.out.println(str2+"-"+str2.matches("^\\p{InGreek}{2}\\d{6}")); //Δ�123456-false

   System.out.println(str1.equals(str2)); //false
}

The same String doesn’t match regex when read from keyboard.
What causes this problem, and how can we solve this?
Thanks in advance.

EDIT: I used System.console() for input and output.

public static void main(String[] args) throws IOException {
        PrintWriter pr = System.console().writer();

        String str1 = "ΔΞ123456";
        pr.println(str1+"-"+str1.matches("^\\p{InGreek}{2}\\d{6}")+"-"+str1.length());

        String str2 = System.console().readLine();
        pr.println(str2+"-"+str2.matches("^\\p{InGreek}{2}\\d{6}")+"-"+str2.length());

        pr.println("str1.equals(str2)="+str1.equals(str2));
}

Output:

ΔΞ123456-true-8
ΔΞ123456
ΔΞ123456-true-8
str1.equals(str2)=true

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T02:05:04+00:00Added an answer on May 19, 2026 at 2:05 am

    If you use Windows, it may be caused by the fact that console character encoding (“OEM code page”) is not the same as a system encoding (“ANSI code page”).

    InputStreamReader without explicit encoding parameter assumes input data to be in the system default encoding, therefore characters read from the console are decoded incorrectly.

    In order to correctly read non-us-ascii characters in Windows console you need to specify console encoding explicitly when constructing InputStreamReader (required codepage number can be found by executing mode con cp in the command line):

    BufferedReader br = new BufferedReader(
        new InputStreamReader(System.in, "CP737")); 
    

    The same problem applies to the output, you need to construct PrintWriter with proper encoding:

    PrintWriter out = new PrintWrtier(new OutputStreamWriter(System.out, "CP737"));
    

    Note that since Java 1.6 you can avoid these workarounds by using Console object obtained from System.console(). It provides Reader and Writer with correctly configured encoding as well as some utility methods.

    However, System.console() returns null when streams are redirected (for example, when running from IDE). A workaround for this problem can be found in McDowell’s answer.

    See also:

    • Code page
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code:public class duplicate { public static void main(String[] args)throws IOException { System.out.println(Enter words separated
public static void main(String[] args) throws IOException, URISyntaxException,TransformerException { TransformerFactory factory = TransformerFactory.newInstance(); String
My code is as such: public static void main(String args[]) throws IOException { String
I have a problem with this code public static void main(String[] args) throws IOException,
The following code: public class TestInnerClass { public static void main(String[] args) throws IOException
public static void main(String[] args) throws IOException { String st3[]=new String[]{сто, двести, триста, sdf,
import java.io.*; public class TerminateWhen { public static void main(String args[]) throws IOException {
as the title. public static void main(String[] args) throws InterruptedException { Thread thread =
import java.io.*; import java.util.*; public class Readfilm { public static void main(String[] args) throws
public class Main { public static void main(String[] args){ Class2 class2Object = new Class2();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.