[Solved] Iterate through every permutation of an array of numbers

Technically, a permutation means a re-ordering of some elements, so for example, [3,1,2] is a permutation of [1,2,3]. What you’re asking for is equivalent to iterating over a Cartesian product, hence the Python function being named product. As you correctly note, recursion is the way to go here. This is because generating all sequences for … Read more

[Solved] Adding Binary number in java

dec1 = decimal number representation of num1(binary) k = binary factor dec1 = dec1 + (num1%10) * k; Here he is building the decimal number from binary number. (num1%10) gives the last digit of the number. Ex: num1 = 110 First iteration: dec1 = 0 +(110 %10) *1 dec1 = 0 k = 1*2 Second … Read more

[Solved] Filtering on unrelated variable in java streams

A one possible solution is to define a custom predicate like this: Predicate<Item> myPredicate = item -> randomVar == 42; Then you can use the predicate in your stream: items .stream() .filter(myPredicate) .forEach(System.out::println); solved Filtering on unrelated variable in java streams

[Solved] How to retrieve previous button state when start application again?

try this SharedPreferences sp=getSharedPreferences(“Button”, Context.MODE_PRIVATE); SharedPreferences.Editor Ed=sp.edit(); // get status of button to set backround from SharedPreferences in oncrate() methosd if(sp.getBoolean(“button1”,false)){ b1.setBackgroundColor(Color.WHITE); }else { b1.setBackgroundColor(Color.GREEN); } if(sp.getBoolean(“button2”,false)){ b2.setBackgroundColor(Color.WHITE); }else { b2.setBackgroundColor(Color.GREEN); } // set button background status in SharedPreferences b1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { b1.setBackgroundColor(Color.GREEN); b2.setBackgroundColor(Color.WHITE); Ed.putBoolean(“button1”, true); Ed.commit(); } } … Read more

[Solved] What does this Java syntax mean? (` Class

Ok, so the first parameter of the function is a List<E> named Arraylist (You shouldn’t capitalize variables in Java, name it as such arrayList). The second parameter is a Class<? extends E> named clazz. Check manub’s explaination of Class<?>: Class is a parameterizable class, hence you can use the syntax Class<T> where T is a … Read more

[Solved] How can I add two button (one is back, one is next) under scrollview that filled with textview and imageview in a screen, android?

This is what XML is for. Create your layout in xml and import it via java. You will want to create your own “bar layout” for the bars in the center, though you could I suppose, fill 3 separate LinearLayouts to achieve the same effect, making a separate layout and putting in it here will … Read more

[Solved] Firebase Query help me

To solve this problem, move the declaration of your final int[] ndomande = {14}; array inside the onDataChange() method, otherwise it will be always null. public void onDataChange(DataSnapshot dataSnapshot) { //Toast.makeText(PlayTest.this, “FIN QUI “,Toast.LENGTH_SHORT).show(); final int[] ndomande = {14}; for (DataSnapshot messageSnapshot : dataSnapshot.getChildren()) { //Toast.makeText(PlayTest.this, “QUI “,Toast.LENGTH_SHORT).show(); long numero_domande = (long) messageSnapshot.getValue(); ndomande[0] = … Read more

[Solved] Compiler does not recognize button

The Button and View classes need to be imported; e.g. import android.widget.Button; import android.view.View; Your class is in the default package, so all classes that it uses (apart from those in the java.lang package) need to be imported. The reference to button_id is probably a mistake. Button mButton = (Button) findViewById(R.id.button); final Button button = … Read more

[Solved] Loop is infinitly looping or IndexOutOfBoundsException: Index =4, Size =2

You are getting IndexOutOfBoundsException on restrictedAreaArrayList, You are adding imageInfos to restrictedAreaArrayList with restrictedAreaArrayList.add(i,imageInfos); ith index may not exist in restrictedAreaArrayList you can just add it restrictedAreaArrayList.add(imageInfos) Or if you want to preserve the order then make restrictedAreaArrayList’s size equal to imageInfosArrayList you can do that by creating it with restrictedAreaArrayList = new ArrayList<ImageInfos>(imageInfosArrayList.size()); Or … Read more

[Solved] Need help to convert data in an ArrayList to Strings and Pass each of them as String parameters to a function

If getTranscript is void: for (String s : slist) { getTranscript(s); } If getTranscript returns a string and you would like to save it: ArrayList<String> transcripts = new ArrayList<String>(); for (String s : slist) { transcripts.add(getTranscript(s)); } 1 solved Need help to convert data in an ArrayList to Strings and Pass each of them as … Read more