package programs;
import java.util.Arrays;
public class SumofArray1 {
public static void test() {
int[] arr = {1,2,3,4,5,6,7,8,9};
int sum =0;
for (int i : arr) {
sum =sum+i;
}
System.out.println(sum);
}
public static void repeatednumber() {
int[] arr = {10,2,2,3,5,5,6,8,8};
Arrays.sort(arr);
for (int i = 1; i < arr.length; i++) {
if (arr[i] == arr[i-1]) {
// System.out.println("Duplicate elements : "+ arr[i]);
} else {
System.out.println("---------------------------------");
System.out.println("Distinict Elements - "+ arr[i]);
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
repeatednumber();
}
}
import java.util.Arrays;
public class SumofArray1 {
public static void test() {
int[] arr = {1,2,3,4,5,6,7,8,9};
int sum =0;
for (int i : arr) {
sum =sum+i;
}
System.out.println(sum);
}
public static void repeatednumber() {
int[] arr = {10,2,2,3,5,5,6,8,8};
Arrays.sort(arr);
for (int i = 1; i < arr.length; i++) {
if (arr[i] == arr[i-1]) {
// System.out.println("Duplicate elements : "+ arr[i]);
} else {
System.out.println("---------------------------------");
System.out.println("Distinict Elements - "+ arr[i]);
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
repeatednumber();
}
}
No comments:
Post a Comment