You are viewing a single comment's thread. Return to all comments →
its a java code, can anyone tell me what's wrong with this code
import java.io.; import java.util.;
public class Solution {
public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner scanner = new Scanner(System.in); int userInt = scanner.nextInt(); HashSet<Double> s = new HashSet<Double>(); for(int i=0; i<userInt; i++) { Scanner sc = new Scanner(System.in); String userStr = sc.nextLine(); String[] str = userStr.split("\\s"); double n = Double.parseDouble(str[1]); //System.out.println(str[0]); if(str[0].equals("a")) { s.add(n); } else if(str[0] =="r" && s.contains(n)) { s.remove(n); } else if (s.isEmpty()) { System.out.println("Wrong!"); continue; } ArrayList<Double> arr = new ArrayList(s); Collections.sort(arr); if(arr.size()%2==0) { // 0 1 2 3 4 System.out.println((arr.get(arr.size()/2)+arr.get((arr.size()/2)-1))/2); } else { System.out.println(arr.get( arr.size()/2)); } } }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Median Updates
You are viewing a single comment's thread. Return to all comments →
its a java code, can anyone tell me what's wrong with this code
import java.io.; import java.util.;
public class Solution {
}