[Solved] String Permutation method that returns String[]

Try the following. I don’t know what sort you’re applying (if any), so I’m just not doing one. public String[] permutations(String str) { if (str.length() == 0) { return new String[0]; } else if (str.length() == 1) { String[] s = new String[1]; s[0] = str; return s; } Set<String> permutations = new HashSet<>(); for … Read more

[Solved] Rewriting a conditional chain as a sequence of one-liners

This code would not compile: if (gamepad1.left_stick_y>50) mainArm.setDirection(DIRECTION_FORWARD), mainArm.setPower(50); // ^ Your attempt at converting multiple operations into one by placing a comma would not work: JLS 15.27: Unlike C and C++, the Java programming language has no comma operator. One approach is to allow changing power and direction in a single call: if (gamepad1.left_stick_y … Read more

[Solved] What is the program for string conversion like a2b4c5 into aabbbbccccc in java language?

public class Program { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String str = “a11b4c5”; System.out.println(getAnswerByPassingString(str)); } public static String getAnswerByPassingString(String str) { String number = “”; String letter = “”; String resStr = “”; ArrayList<String> stringList = new ArrayList<String>(); ArrayList<String> numbersList = new ArrayList<String>(); for … Read more

[Solved] Add an array to an array in Java [closed]

You can use List<List<String>> instead for example : List<List<String>> arrList = new ArrayList<>(); for (int i = 0; i < 5; i++) { List<String> arr = new ArrayList<>(); arr.add(“a” + i); arr.add(“b” + i); arr.add(“c” + i); arrList.add(arr); } System.out.println(arrList); Output [[a0, b0, c0], [a1, b1, c1], [a2, b2, c2], [a3, b3, c3], [a4, b4, … Read more

[Solved] Error Handling mechanism [closed]

Compilers are not predictive to get the result exactly in the format humans want. They obviously work on the limited syntax and semantics rule and as per some grammar (or rules you can say). Errors are also Exceptions in Java that define exceptions which aren’t expected to be caught under normal circumstances. So basically, an … Read more

[Solved] How to subtract 30 days from current date [closed]

Use below code Calendar c = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd”); String date = new SimpleDateFormat(“yyyy-MM-dd”, Locale.getDefault()).format(new Date()); c.setTime(sdf.parse(date)); c.add(Calendar.DATE, -30); Date newDate = c.getTime(); solved How to subtract 30 days from current date [closed]