Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package vn.com.hoangminh.Physics;
- import java.util.Scanner;
- public class DistinctNumber {
- public static void main(String[] args) {
- //Khai báo Var
- Scanner input = new Scanner(System.in);
- System.out.print("Chương trình loại bỏ các số bị lặp lại trong các số đã nhập \nNhập số chữ số cần nhập : ");
- int soChuSo = input.nextInt();
- int[] nhap = new int[soChuSo];
- int[] xuat = new int[soChuSo];
- int j = 0;
- //Declare input vào array
- for( int i = 0 ; i < soChuSo ; i++ ) {
- System.out.print("Nhập số thứ " + (i+1) +" : ");
- nhap[i] = input.nextInt();
- }
- //Tìm số bị lặp và đăng output
- for ( int a = 0 ; a < soChuSo ; a++ ) {
- for ( int b = 0 ; b < soChuSo ; b++ ) {
- if( nhap[a] == xuat[b] ) break;
- if( b == soChuSo - 1 ) {
- xuat[j] = nhap[a];
- j++;
- }
- }
- }
- //Output
- System.out.print("Kết quả sau khi loại bỏ các số bị lặp : ");
- for ( int c = 0 ; c < j ; c++ ) {
- System.out.print(" " + xuat[c] );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment