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); } }

14th Apr 2021, 11:22 AM
Sachin Saxena
Sachin Saxena - avatar
2 Réponses
0
What output you want?
14th Apr 2021, 11:56 AM
santhosh Kumar
santhosh Kumar - avatar
0
it counts unique numbers in array, but there is wrong semicolon after if(); if (val==true) //; c++;
14th Apr 2021, 10:37 PM
zemiak