In: Computer Science
import java.util.*;
public class DataAnalysis{
static Set<String> Data_NaN(Set<String>
set){
Set<String> set2 = new
HashSet<String>();
for (String temp : set) {
temp = temp.replaceAll(
"[^0-9]", "");
if(!(set.isEmpty())){
set2.add(temp);
}
}
return set2;
}
public static void main(String args[])
{
// create empty set
Set<String> set = new HashSet<String>();
// {3, 25, 33, 21, 55, 43, 78, 31, 33, 75, 43, 11, 36, 4, 10, 99,
A, B, C}
// add values one by one in set
set.add("03");
set.add("25");
set.add("33");
set.add("21");
set.add("55");
set.add("43");
set.add("78");
set.add("31");
set.add("33");
set.add("75");
set.add("43");
set.add("11");
set.add("36");
set.add("04");
set.add("10");
set.add("99");
set.add("A"); set.add("B"); set.add("C");
// print input set
System.out.println("Set: " + set);
// call funtion Data_NaN to filter out non-numerical data
System.out.println("After filtering nonnumerical data- Set:
"+Data_NaN(set));
// call funtion Data_Min to calculate min value
System.out.println("Minimum number from set is=
"+Data_Min(set));
}
static String Data_Min(Set<String> set) {
String obj =
Collections.min(set);
return obj;
}
}
output: After filtering nonnumerical data: [33, 55, 11, 99, ,
78, 25, 36, 3, 4, 31, 75, 21, 43, 10]
Minimum value After filtering nonnumerical data:
Question:. this is a dataset given{3, 25, 33, 21, 55, 43, 78, 31,
33, 75, 43, 11, 36, 4, 10, 99, A, B, C} why Data min method does
not print any thing? I need to find maximum value, average value,
median, mode, order it small to large using numerical data of given
dataset in separate methods.
import java.util.*;
public class DataAnalysis {
static Set<String> Data_NaN(Set<String> set) {
Set<String> set2 = new HashSet<String>();
for (String temp : set) {
temp = temp.replaceAll("[^0-9]", "");
if (!(set.isEmpty())) {
set2.add(temp);
}
}
return set2;
}
public static void main(String args[]) {
// create empty set
Set<String> set = new HashSet<String>();
// {3, 25, 33, 21, 55, 43, 78, 31, 33, 75, 43, 11, 36, 4, 10, 99, A, B, C}
// add values one by one in set
set.add("03");
set.add("25");
set.add("33");
set.add("21");
set.add("55");
set.add("43");
set.add("78");
set.add("31");
set.add("33");
set.add("75");
set.add("43");
set.add("11");
set.add("36");
set.add("04");
set.add("10");
set.add("99");
set.add("A");
set.add("B");
// print input set
System.out.println("Set: " + set);
// call funtion Data_NaN to filter out non-numerical data
System.out.println("After filtering nonnumerical data- Set: " + Data_NaN(set));
// call funtion Data_Min to calculate min value
System.out.println("Minimum number from set is= " + Data_Min(Data_NaN(set)));
}
static String Data_Min(Set<String> set) {
// here it will compare the numbers as strings so we will not get the correct
// so we should convert it as int and find min
int min = Integer.MAX_VALUE;
for (String s : set) {
if (s.trim().length() != 0) {
int i = Integer.parseInt(s);
if (i < min)
min = i;
}
}
return Integer.toString(min);
}
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME