[java] laba7-OOP
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in); //создаём сканер для считывания данных с клавиатуры
- int n = 0; //создаём переменную n
- char[] letters = { 'Б', 'В', 'Г', 'Д', 'Ж', 'З', 'Й', 'К', 'Л', 'М', 'Н', 'П', 'Р', 'С', 'Т', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ'}; //создаём массив из прописных согласных букв
- System.out.print("Введите n: "); //выводим сообщение на экран
- n = scanner.nextInt(); //считываем n
- char[] result = new char[n]; //создаём массив из n символов
- for (int i = 0; i < n; i++) { //перебираем этот массив
- int randomIndex = (int)(Math.random() * letters.length); //получаем рандомный индекс [0;letters.length)
- result[i] = letters[randomIndex]; //запоминаем рандомную букву
- }
- System.out.print("Результат программы: ");
- for (int i = 0; i < n; i++) {
- System.out.print(result[i] + " "); //выводим результат на экран
- }
- }
- }
Editor
You can edit this paste and save as new: