Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.84 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.util.InputMismatchException;
  3. import java.util.Scanner;
  4.  
  5.  
  6. public class Main {
  7.  
  8.  
  9.     public static class Applet1c extends JApplet {
  10.         public void init() {
  11.             getContentPane().add(new JLabel("Дмитрий Пинчук"));
  12.         }
  13.     }
  14.  
  15.  
  16.     public static void main(String[] args) {
  17.         JApplet applet = new Applet1c();
  18.         JFrame frame = new JFrame("Лабораторна робота");
  19.  
  20.  
  21.         frame.getContentPane().add(applet);
  22.         frame.setSize(200, 100);
  23.         applet.init();
  24.         applet.start();
  25.         frame.setVisible(true);
  26.     task2();
  27.  
  28.     }
  29.     public static void task2(){
  30.         int counter=0;
  31.         int ch= inputInt("Введите количество чисел");
  32.         int[] array = new int[ch];
  33.         for (int i = 0; i <array.length ; i++) {
  34.             array[i]= inputInt("Введите число");
  35.         }
  36.         for (int i = 0; i <array.length ; i++) {
  37.             int a= array[i];
  38.             char[] temp= String.valueOf(array[i]).toCharArray();
  39.             char arraytemp = temp[0];
  40.             for (int j = 1; j < temp.length; j++) {
  41.                 if (arraytemp==temp[j]){
  42.                     counter++;
  43.                 }
  44.             }
  45.             if (counter==temp.length-1){
  46.                 System.out.println("Щасливе число");
  47.                 System.out.println( array[i]);
  48.             }
  49.  
  50.             counter=0;
  51.         }
  52.  
  53.     }
  54.     public static int inputInt(String text){
  55.         while(true) {
  56.             try {
  57.                 System.out.println(text);
  58.                 Scanner sk = new Scanner(System.in);
  59.                 return  sk.nextInt();
  60.             } catch (InputMismatchException ex){
  61.                 System.out.println("Неверное число");
  62.             }
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement