Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.myapplication;
- import android.widget.Button;
- import androidx.appcompat.app.AppCompatActivity;
- import java.util.Collections;
- public class MainActivity extends AppCompatActivity {
- TextView textView;
- Button button;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- textView = (TextView) findViewById(R.id.textview);
- button = (button) findViewById(R.id.button);
- button.setOnClickListener((view) {
- ArrayList<Integer>list = new ArrayList<~>();
- for (int i = 1; i <=49; i++)
- {
- list.add(i);
- }
- Collections.shuffle(list);
- ArrayList<Integer> chosen = new ArrayList<~>();
- for (int = 0; i < 6; i++)
- {
- chosen.add(list.get(i));
- }
- Collections.sort(chosen);
- StringBuilder sb = new StringBuilder();
- for(int i: chosen)
- {
- sb.append(String.valueOf(i));
- sb.append(", ");
- }
- textView.setText(sb.toString().replaceAll(regex ", $", replacement ""));
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement