[Solved] I have to print a series using for loop

The following block should generate the series as you described it. int numberOfLines = 4; int numberOfDigitsPerLine = 5; for (int i=1; i<numberOfLines+1; i++){ for(int j=1; j<=numberOfDigitsPerLine; j++) { if(j>=i) { System.out.print(j); } else { System.out.print(i); } } System.out.println(); } Change numberOfLines and numberOfDigitsPerLine as necessary. Elaboration: First you must analyze the series, by the … Read more

[Solved] why is it that we can’t use ArrayList.get(-1) to get the last element of the ArrayList in java? it works in python though [closed]

First, Java is not Python (although Jython implements Python in Java). Second, you should read the JavaDoc on ArrayList – that is it throws an Exception, IndexOutOfBoundsException – if the index is out of range (index < 0 || index >= size()) Finally, you can do this myList.get(myList.size() – 1); to get this last element … Read more

[Solved] Why is this code giving me a strange output

This is not because of the complier. It is happening because you are doing i /= 10; //slice end So when you do 13.4 after the first run it wont give you 1.34 it will give you something like 1.339999999999999999 which is 1.34. Check Retain precision with double in Java for more details. If you … Read more

[Solved] Defining Proper Classes with Java [closed]

MyClass and MyObj are the wrong way around, it should be: MyClass MyObj = new MyClass(); Otherwise you are trying to declare an instance of MyObj which doesn’t exist. Instead you declare an instance of MyClass and name this MyObj. Hopefully that makes sense to you 🙂 solved Defining Proper Classes with Java [closed]

[Solved] Recursive definition solution

To get a working recursive solution you need a base case, for example a == 0, and then work yourself down towards the base case by recursively calling yourself. The solution for question 1 could be something along the lines of this, that decreases the a argument until it reaches 0: int multiply(int a, int … Read more

[Solved] Output incorrect [duplicate]

Let’s debug this a little, add a few system outs… this is what you would see for each step 100.0 – 5.0 95.0 + 10.0 105.0 + 13.0 118.0 your value array is {100,5,10,13} and your operator array is {-,+,+} you have not mapped a = 100, b = 5, c= 10, d = 13, … Read more

[Solved] How can I convert a datetime string into an integer datatype?

A first step will be to convert the time in HH:MM:SS format (which is how your string is formatted) to that of seconds as per the following: String timerStop1 = String.format(“%02d”, hours) + “:” + String.format(“%02d”, minutes) + “:” + String.format(“%02d”, seconds); String[] timef=timerStop1.split(“:”); int hour=Integer.parseInt(timef[0]); int minute=Integer.parseInt(timef[1]); int second=Integer.parseInt(timef[2]); int temp; temp = second … Read more