Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.a2020_01_29_kolodziej;
- import androidx.appcompat.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Random;
- public class Losowanie extends AppCompatActivity
- {
- TextView wyniki;
- Button losuj;
- EditText podajliczbe;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_losowanie);
- wyniki=findViewById(R.id.textView);
- losuj=findViewById(R.id.button4);
- podajliczbe=findViewById(R.id.editText);
- }
- public void losuj(View view){
- Random los=new Random();
- int tab[]=new int[6];
- wyniki.setText("");
- for (int i=0;i<6;i++) {
- tab[i]=los.nextInt(49)+1;
- wyniki.setText(wyniki.getText()+Integer.toString(tab[i])+" ; ");
- }
- }
- public void losuj1(View view) {
- ArrayList<Integer> liczby = new ArrayList<>();
- wyniki.setText("");
- int zmienna;
- String text = (String) podajliczbe.getText().toString();
- zmienna = Integer.parseInt(text);
- try {
- zmienna = Integer.parseInt(text);
- } catch(NumberFormatException nfe) {
- System.out.println("Could not parse " + nfe);
- }
- for(int i = 20; i < 200; ++i) {
- liczby.add(i);
- }
- Collections.shuffle(liczby);
- for(int i = 0; i < zmienna; ++i) {
- wyniki.setText(wyniki.getText()+Integer.toString(liczby.get(i))+" ; ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement