dimanche 3 février 2019

How can I change the characters to string like "' R2 " " U' " "L"? (Andorid Studio, Java)

    package com.rekordea.scramblegenerator;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.util.Random;


public class MainActivity extends AppCompatActivity {
private Button button;
private TextView textView;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    button = findViewById(R.id.button);
    textView = findViewById(R.id.textView);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //change the scramble length
            textView.setText(getRandomString(16||17||18||19));
        }
    });
}

public static String getRandomString(int i) {
    final String characters = "RULFBDB2'";
    StringBuilder result = new StringBuilder();
    while (i > 0) {
        Random rand = new Random();
        result.append(characters.charAt(rand.nextInt(characters.length())));
        i--;
    }
 return result.toString();
    }
}

So I am trying to make a simple Android Studio program that should give a text like this when pressed a button: B' F U' R2 B L2 F R' D2 U2 L2 B' D' R2 B' U' B2 R2 U' F L' R U' R U B' U' L B' U2

But I can't change the characters to strings since I am a noob at Java. Thanks.




Aucun commentaire:

Enregistrer un commentaire