[Solved] Java sort 4 arrays into 1 array

Step 1: Combine all the arrays Step 2: Sort arrays using Arrays.sort(array); Step 3: Remove the duplicates. int[] a = {1,2,3,4,5}; int[] b = {1,2,3,4,5,6}; int[] c = {1,3,7}; int[] d = {2,3,4,8,9,10}; int[] resultArray1 = new int[a.length+b.length+c.length+d.length]; int arrayIndex = 0; for (int i=0; i< a.length ; i++, arrayIndex++ ) { resultArray1[arrayIndex] = a[i]; … Read more

[Solved] Inserting punctuation marks in a java String [closed]

How about this: String greetings = “Hello” + “,” + ” how are you”; Or this: String greetings = “Hello how are you”; greetings = greetings.substring(0, 5) + “,” + greetings.substring(5); Or this: String greetings = “Hello how are you”; greetings = new StringBuilder(greetings).insert(5, “,”).toString(); Inserting a punctuation mark is trivial if you know where … Read more

[Solved] Printing Boolean Array in Java [closed]

It looks like you do not want to print boolean array: it’s of little use. You need to print the primes from the Sieve of Eratosthenes, which can be done by enumerating the indexes, checking if primes[i] is true, and printing the index if it is. boolean primes = sieve(100); for (int i = 0 … Read more

[Solved] Invalid method declaration, return type required

Constructor name should be same as your class name. your class name is Rectangle1 thus your Constructor name should be the same as well, currently java compiler this it as an method without a return type, thus it complains. public Rectangle(double width, double height){ should be public Rectangle1(double width, double height){ 6 solved Invalid method … Read more

[Solved] regex for splitting a string while ignoring the brackets [duplicate]

You can use the below regex to achieve your requirement: [ ](?=[^\)]*?(?:\(|$)) Explanation of the above regex: [ ] – Represents a space character. (?=[^\)]*?(?:\(|$)) – Represents a positive look-ahead asserting everything inside of (). (?:) – Represents a non-capturing group. | – Represents alternation. $ – Represents the end of the test String. You … Read more

[Solved] allow specif regex only in a block

Ok, first you should probably write your regex as: [\u0600-\u06FF\uFB8A\u067E\u0686\u06AF \.!?:)(,;1234567890%\-_#]+$ Here %\-_ inside […] means % or – or _ while your %-_ means “any symbol with the code from % to _. Try /[%-_]/.exec(“)”) and see what I mean: the ) symbol is in that range. I also put \. which highlights that … Read more

[Solved] Why am I getting “No suitable driver found for jdbc:mysql://localhost:3306/test2”?

You need to load the com.mysql.jdbc.Driver driver class. private static final String DRIVER_NAME=”com.mysql.jdbc.Driver”; Look at the official documentation: The name of the class that implements java.sql.Driver in MySQL Connector/J is com.mysql.jdbc.Driver. The org.gjt.mm.mysql.Driver class name is also usable for backward compatibility with MM.MySQL, the predecessor of Connector/J. Use this class name when registering the driver, … Read more

[Solved] Printing Diamonds Java Output not exactly as required

You can modify your inner loop logic when printing lower half of the diamond. //Printing j *’s at the end of each row int mid = (row+1) / 2; for (int j = row; j > 0; j–) { if(i==0 && j==mid) System.out.print(“o “); else System.out.print(“* “); } 3 solved Printing Diamonds Java Output not … Read more

[Solved] Removing ASCII characters in a string with encoding

I gave a unsatisfying answer, thanks to @OlegEstekhin for pointing that out. As noone else answered yet, and a solution is not a two-liner, here it goes. Make a wrapping InputStream that throws away escape sequences. I have used a PushbackInputStream, where a partial sequence skipped, may still be pushed back for reading first. Here … Read more

[Solved] I am new in using ArrayLists. Array Out of Bounds, Array seems to be empty, but have been adding Strings to it already

First of all, and that’s supposed to solve the problem. If you use an ArrayList you should check its documentation. When you supposed to go through a simple array you use “nameOfArray.length”, right? Well, the ArrayList has the method “.size()” which bascialy has the same use. So your loop would be better this way : … Read more