-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathno: of slices
54 lines (46 loc) · 1.07 KB
/
no: of slices
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.io.*;
import java.util.*;
class fruits {
static int numberofSlices(int arr[], int n)
{
int res = 1;
// Pick all elements one by one
for (int i = 1; i < n; i++) {
int j = 0;
for (j = 0; j < i; j++)
if (arr[i] == arr[j])
break;
// If not printed earlier,
// then print it
if (i == j)
res++;
}
return res;
}
// Driver code
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter no. of fruits:");
int n = sc.nextInt();
int arr[] = new int[n];
System.out.println("Enter the weights of fruits:");
for(int i = 0; i < n; i++)
{
arr[i] = sc.nextInt();
}
System.out.print("No: of slices required is:");
System.out.println(numberofSlices(arr, n));
}
}
/*OUTPUT
Enter no. of fruits:6
Enter the weights of fruits:
10
20
10
30
20
10
No: of slices required is:3
*/