[Solved] android change first blank to “AA”

Try this code,you may got the expected answer, String str=”a b c”; boolean a1 = true ; StringBuilder strbu = new StringBuilder(); for(int i=0 ; i<str.length();i++) { Character b = str.charAt(i); if(b.equals(‘ ‘) && a1 == true ) { a1 = false; strbu = strbu.append(“AA”); } else { strbu = strbu.append(b); } } Log.e(“str”,”string:”+strbu.toString()); solved … Read more

[Solved] Solve Exception handling

Exception classification help use understand what exactly is the issue at hand easily even before we see the description. It is a first sigth informer to the developer to understand the issue. For example if you are getting a NullPointerException / ArithemeticException and if you just say “Exception occured” can we understand anything? without a … Read more

[Solved] How to create a consecutive number by month

Well, your question is not clear. But as far as I understand you need help to get the date. You can use Calendar() or Date(), use something like this Calendar.get(Calendar.MONTH)to get the month and year (or simply parse to string and substring where you want). Regarding the number at the beginning, I will assume (again, … Read more

[Solved] Exception in thread “main” java.lang.StringIndexOutOfBoundsException: String index out of range: 0 [closed]

nextDouble() leaves the newline in the input stream, so when you then call nextLine().charAt(0) the result of nextLine() is an empty string. Remove the newline from the stream, or use next(), as you did above. 5 solved Exception in thread “main” java.lang.StringIndexOutOfBoundsException: String index out of range: 0 [closed]

[Solved] Java – interface -instsnceof

JLS 15.20.2 states: If a cast of the RelationalExpression to the ReferenceType would be rejected as a compile-time error (ยง15.16), then the instanceof relational expression likewise produces a compile-time error. In such a situation, the result of the instanceof expression could never be true. In this case (Intf) obj is not a compile time error … Read more

[Solved] Count letters in a string

You can solve the problem by following the steps below like QBrute correctly pointed out. public String countMatches(String main) { //Create an array of the alphabets length main = main.toLowerCase(); int[] foundArray = new int[26]; String output = “”; //Create an alphabets array String[] alphabets = “a b c d e f g h i … Read more

[Solved] How to equal php answer?(.equals not working) [closed]

The most likely case here can be that the answer has leading/trailing white spaces. You need to trim() those out. if (answer.trim().equals(“OK”)) { You did not initially mention in the question that the answer had extra string besides “OK”. In that case, you either need to remove other stuffs(using a regex may be), or use … Read more

[Solved] Creating Java nested FOR LOOPS and conditional statements without iterating over and over [closed]

If the length of user[] and pass[] is always equal, you can try this: Update: This is much more simpler: String currentUser = “empty”; boolean login=false; for(int j = 0; j < user.length; j++){ if( username.equals(user[j]) && password.equals(pass[j])){ currentUser = user[j]; login=true; break; } } if(login) System.out.println(“Hello ” + currentUser+ “!” ); else System.out.println(“Incorrect Login!” … Read more

[Solved] Is this regex pattern wrong? [closed]

I guess it is wrong in your sense. I suspect you’re looking for this. String pattern = “(\\D*)(\\d+)(.*)”; Maybe you want to check reluctant quantifiers too. http://docs.oracle.com/javase/tutorial/essential/regex/quant.html 13 solved Is this regex pattern wrong? [closed]