[Solved] How to select n numbers from n sets of different size?

You can use cartesian product on sets in Java by the use of com.google.common.collect.Sets. FOR EXAMPLE Set<Integer> s1=new HashSet<Integer>(); s1.add(1);s1.add(4);s1.add(5); Set<Integer> s2=new HashSet<Integer>(); s2.add(2);s2.add(3);s2.add(6); Set<Integer> s3=new HashSet<Integer>(); s3.add(7);s3.add(8);s3.add(8); Set<List<Integer>> set=Sets.cartesianProduct(s1,s2,s3); //Give type safety warning for(List<Integer> l:set){ System.out.println(l); } OUTPUT [1, 2, 7] [1, 2, 8] [1, 3, 7] [1, 3, 8] …. NOTE If you … Read more

[Solved] Syntax error on token “else”, delete this token [closed]

your code is missing braces ( that’s these: {} BTW). It’s ok if your if statement involves only a single line, however i’d advise to use them anyway for readability. Overall, your code should look similar to: import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.ie.InternetExplorerDriver; public class gg { public static void main(String[] args) { … Read more

[Solved] String to find A character [duplicate]

If you’re beginner check this : String s1=” read the documentation for the methods of String”; //your string char ch=s1.charAt(s1.indexOf(‘A’)); //first appearance of character A int count = 0; for(int i=0;i<s1.length();i++) { if(s1.charAt(i)==’A’){ //if character at index i equals to ‘A’ System.out.println(“number of A:==”+ch); count++; //increment count } } System.out.println(“Total count of A:==”+count); If you’re … Read more

[Solved] Advanced AlarmManager situation [closed]

You can use setRepeating(..) – which is described in detail here. If you want to repeat the alarm in an interval that is not provided in the available constants just calculate the correct amount of milliseconds (e.g. for a week: 1000 * 60 * 60 * 24 * 7 (1 sec * 60 -> 1 … Read more

[Solved] Why there are empty string while trying to split a string in Java? And how to fix it?

It’s because you’re splitting by a single character, you would have to do this eagerly: String[] Operators = stringNumbers.split(“[0-9.]*”); Or you can filter the results: String[] Operators = Arrays.stream(stringNumbers.split(“[0-9.]”)) .filter(str -> !str.equals(“”)) .toArray(String[]::new); 5 solved Why there are empty string while trying to split a string in Java? And how to fix it?

[Solved] Diamond with a blank space inside

For the lower set of symbol you need to put a space before printing the star.Modifying the condition to s>=1, makes the flow enter the loop and prints a space.Earlier it was not entering the loop.This should get you the required output. for(int s = y; s >= 1; s–) { System.out.print(” “); } solved … Read more

[Solved] Sorting TreeMap alphabetically

Eric Berry wrote a handy class that compares Strings by human values instead of traditional machine values. Below is a modified version of it along with Object comparator (what I think you are looking for) and its testing class. An example on how to use the string comparator: Map<String,String> humanSortedMap = new TreeMap<>(new AlphaNumericStringComparator()); An … Read more

[Solved] What is this parameter used for?

Regardless of what I input in the parameter for this, nothing changes?? It’s because the filename argument is not used anywhere in the ReadNumberFile(String filename) method.. As it seems, this parameter (filename) represents the name (or maybe the fully-qualified path) of a file that should be read. If that’s the case, you should change this … Read more

[Solved] If the first name, last name and the nick name starts with the special chars [closed]

You can use String#matches() to check if a name begins with any of the special characters on your blacklist: if (name.matches(“(?:!|@|#|\\$|%|\\^|&|\\*|\\(|\\)|_|\\+|\\?|>|‌​<).*”)) { System.out.println(“Enter valid name”); } Another way: String specialChars = “!@#$%^&*()_+?><“; if (specialChars.indexOf(name.charAt(0)) != -1) { System.out.println(“Enter valid name”); } solved If the first name, last name and the nick name starts with the … Read more

[Solved] Could I use C++ code with JAVA code? [closed]

It sounds like what you need is a way to call C++ code from inside a Java program. Refer to this tutorial http://www.ibm.com/developerworks/java/tutorials/j-jni/j-jni.html It explains how the Java Native Interface, part of the Java Software Development Kit, can be used to call C++ code from Java and Java code from C++ programs. solved Could I … Read more

[Solved] JAVA: I have to write a program to read “sentences” from a file and and then count the number of words and vowels per sentence [closed]

Couple of issues: You are using last user entered sentence while you should use text that you read from file like below: StringTokenizer words = new StringTokenizer(text); numberofwords=numberofwords+words.countTokens(); for (i=0;i<text.length();i++) { ch=text.charAt(i); if (ch==’a’||ch == ‘A’ || ch == ‘e’ || ch == ‘E’ || ch == ‘i’ || ch == ‘I’ || ch == … Read more

[Solved] find substring using match regex

Since this is not quite HTML and any XML/HTML parser couldn’t help it you can try with regex. It seems that you want to find text in form ?drug <someData> ?disease To describe such text regex you need to escape ? (it is one of regex special characters representing optional – zero or once – … Read more