[Solved] Object Orientation, Inheritance, Abstraction [closed]

abstraction – No (you don’t have any abstract members or classes in your code). Encapsulation – yes ( Binding code and data together – the class itself) . polymorphism – no ( no multiple functions with same names ) . inheritance – no (There is no class that inherits this one and vice versa ) … Read more

[Solved] JAVA broken while loop

Mike you Have to use diffrent variables for difflent loop control. create an “n” and it should work Scanner stdin = new Scanner(System.in); System.out.println(“Enter number of rows and columns: “); int row = stdin.nextInt(); int column = stdin.nextInt(); int m = 1; int n = 1; while(m <= column) { while(n <= row) { System.out.println(“*\t”); … Read more

[Solved] Hackerrank string reduction

Your problem is that: reduce(“baab”) = ‘b’ + reduce(“aab”) = ‘b’ + reduce(“b”) = ‘b’ + ‘b’ = “bb” You only look at your first character until you can’t immediately remove it anymore. Then you never look at it again, even if at some point afterwards you actually could remove it. I suppose you could … Read more

[Solved] NumberFormatException – try/catch for parse value

You are catching InputMismatchException but typing a letter instead of a number raise a NumberFormatException. You can use a generic catchexception: try { } catch(Exception e){ //<– Generic exception } Or use multiple catch block: try { } catch(InputMismatchException | NumberFormatException e ){ //<– Multiple exceptions } Updated to explain why InputMismatchException doesn’t work: That’s … Read more

[Solved] String Formatting for a list

You can use String format for this. String format = “%-10s |%10s |%10s |%10s |%10s\n”; System.out.printf(format, values[0], values[1], values[2], values[3], values[4]); above code will give the expected result. EDIT: Using StringUtils for formatting. String result = StringUtils.EMPTY; result = StringUtils.center(values[0], 10) + ‘|’ + StringUtils.center(values[1], 10) + ‘|’+ StringUtils.center(values[2], 15) + ‘|’ + StringUtils.center(values[3], 15) … Read more

[Solved] How do i convert a Set into 2D array in java? [closed]

Let be a: public class MyClassWhithFourFields { String field1; int field2; Object field3; double field4; } Now you can declare a set with this template: Set<MyClassWhithFourFields> mySet = new HashSet<MyClassWhithFourFields>(); In your Set are your objects, which has 4 fields. If you want to declare a 2 dimension array, than what type should be? – … Read more

[Solved] Returning values from thread

Your code, in general, seems pretty solid, but there are several problems. The task you created does the trick, and the progress bar will work, but it uses a thread so returning that the tests are complete without confirming the progress of the thread is wrong. Because the tests are in a thread and the … Read more

[Solved] While loop for multiple inputs

This code does the work. public class PlotPoints { public static void main(String[] args) { Scanner sc = new Scanner(System.in); PlotPoints pp = new PlotPoints(); pp.plotPoints(sc); } public void plotPoints(Scanner keyboard) { int x=1; while (x != -1) { System.out.print(“Enter an x and y coordinate: “); //Read x from user x = keyboard.nextInt(); //Read y … Read more

[Solved] Build an array from existing arrays?

There is no reason for giving type mismatch, while you are adding two int array into another int array. It should work: for(int k = 0; k < 20; k++){ EndTime[k] = StarTime[k] + duration[k]; } Ensure that exp.sample() is really casting into int. Also ensure the arrays are of same type. 1 solved Build … Read more

[Solved] Creating two constructors with objects that call to other java files

would suggest you to please follow below approach to initialize your object through argumented construtor. public class StudentRecord { Student stu; Address addr; public StudentRecord() { Student stu; Address addr; } public StudentRecord(String _fName, String _lName, int _id, double _gpa, String _street, String _city, String _state, int _zip){ this.stu = new Student(_fName, _lName, _id, _gpa); … Read more

[Solved] How call method from Fragment in Activity?

With getActivity() you will get the activity instance, cast it to your activity name and call function from fragments. Assuming activity name as MainActivity ((MainActivity)getActivity()).myFuncInActivity(): 4 solved How call method from Fragment in Activity?