0
Why this gives wrong output
package array; import java.util.Scanner; public class Study { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int size = sc.nextInt(); int arr[] = new int [size]; for(int i=0;i<size;i++) { arr[i] = sc.nextInt(); } dis(arr,size); } public static void dis(int arr[],int size) { int c =0 ; boolean val =true; for(int i=0;i<size;i++) { for(int j=i-1; j>=0;j--) { if(arr[i]==arr[j]) { val=false; break; } } if(val==true); c++; val=true; } System.out.println(c); } }
2 Respostas
0
What output you want?
0
it counts unique numbers in array,
but there is wrong semicolon after if();
if (val==true) //;
c++;