Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.util.InputMismatchException;
- import java.util.Scanner;
- public class Main {
- public static class Applet1c extends JApplet {
- public void init() {
- getContentPane().add(new JLabel("Дмитрий Пинчук"));
- }
- }
- public static void main(String[] args) {
- JApplet applet = new Applet1c();
- JFrame frame = new JFrame("Лабораторна робота");
- frame.getContentPane().add(applet);
- frame.setSize(200, 100);
- applet.init();
- applet.start();
- frame.setVisible(true);
- task2();
- }
- public static void task2(){
- int counter=0;
- int ch= inputInt("Введите количество чисел");
- int[] array = new int[ch];
- for (int i = 0; i <array.length ; i++) {
- array[i]= inputInt("Введите число");
- }
- for (int i = 0; i <array.length ; i++) {
- int a= array[i];
- char[] temp= String.valueOf(array[i]).toCharArray();
- char arraytemp = temp[0];
- for (int j = 1; j < temp.length; j++) {
- if (arraytemp==temp[j]){
- counter++;
- }
- }
- if (counter==temp.length-1){
- System.out.println("Щасливе число");
- System.out.println( array[i]);
- }
- counter=0;
- }
- }
- public static int inputInt(String text){
- while(true) {
- try {
- System.out.println(text);
- Scanner sk = new Scanner(System.in);
- return sk.nextInt();
- } catch (InputMismatchException ex){
- System.out.println("Неверное число");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement