[Solved] Java/Processing is that possible ? void hello(void funktion) [closed]

With Java 8 you can use a lambda. With Processing, you can use an anonymous class that implements a functional interface. Something like this: interface DoFunction{ void do(); } void hello(DoFunction function){ function.do(); } void setup(){ hello(new DoFunction(){ void do(){ println(“here”); } }); } 3 solved Java/Processing is that possible ? void hello(void funktion) [closed]

[Solved] Increasing argument name in a for-loop [closed]

Individual parameters aren’t iterable; you’d need a collection for that. Try changing it to an array instead: public void increment(int increment1, int increment2, int increment3) { int[] array = {increment1, increment2, increment3}; for(int i = 1; i < array.length; i++){ array[i] = 1; } } or public void increment(int[] increment) { for(int i = 1; … Read more

[Solved] How to convert jsonstring to jsonobject in android?

You can try like this, and your root is Json array not jsonobject try { JSONArray jsonArray = new JSONArray(d); if(jsonArray != null) { for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.optJSONObject(i); if(jsonObject == null) { continue; } String name = jsonObject.optString(“name”); String isMe = jsonObject.optString(“isMe”); String time = … Read more

[Solved] sorting (constructor) in Java [closed]

You can define a natural ordering for your class IceCream by implementing the Comparator interface. public class IceCream implements Comparator{ // … final String name; final Date date; public Icecream(String name, Date date){ this.name = name; this.date = date; } public int compare(Object o1, Object o2) { return ((IceCream)o1).date.compareTo(((IceCream)o2).date); } } 3 solved sorting (constructor) … Read more

[Solved] random function in Java [closed]

int randomNumber = ( int )( Math.random() * 9999 ); if( randomNumber <= 1000 ) { randomNumber = randomNumber + 1000; Math.random() is a method that generates a random number through a formula. It returns a double however, so casting is required if you want an integer, float, or etc. The if block makes sure … Read more

[Solved] Crash if digit is more than 9

@Fay Zan Basically you don’t want user to input more than 9 digits for your field, This can be achieved using two ways programmatically or using layout views properties, In you xml simple give this attribute to your EditText android:maxLength=”9″ OR programmatically by checking the length of your field. for example suppose the id of … Read more

[Solved] Google foobar The Cake is not a lie

I think this is a quick working not optimized solution. You basically suppose that you can have n parts. If it works you return, if not you suppose that you can have n-1 part and so one. int result = -1; int len = s.length(); for(int i = len; i > 0; i–){ int n … Read more

[Solved] Java string end with space

Use String.trim() to remove surrounding whitespace and then use String.equals() (not ==, See 15.21 Equality Operators in the Java Language Specification for full details.). Remember that String instances are immutable so String.trim() returns a new String and it is that which must be used in the equals() check. Note that trim() removes leading whitespace also. … Read more