[Solved] Random Number generator in a range and then print length of the sequence [duplicate]

Consider using a while-loop: import java.util.Random; class Sequence { public static void main(String[] args) { Random r = new Random(); int count = 0; int num = -1; System.out.println(“The sequence is:”); while (num != 0) { num = r.nextInt(10); System.out.print(num + ” “); count++; } System.out.printf(“%nThe length of the sequence is: %d%n”, count); } } … Read more

[Solved] Java: Finding duplicate in array [closed]

Try this. do{ System.out.print(“Please enter an integer or -1 to stop: “); input=Integer.parseInt(scan.nextLine()); boolean flag = true; for(int i=0; i<A.length; i++){ if(A[i].equals(input)) { System.out.println(“Duplicate input. Please enter another value: “); flag = false; break; } } if(!flag) { continue; } if(input != -1) //if input is Display.userInput(input); } while(input != -1); 1 solved Java: Finding … Read more

[Solved] How to sum times in java [closed]

Creating DateTime variables and summing them is an approach, but I assume you’re new to Java and give you basic answer to warn you up for some coding and not to go the easy way: String[] timesSplit = times.split(” | “); int hour = 0; int minute = 0; for(int i = 0; i < … Read more

[Solved] How I can implement this hierarchy? [closed]

No, you don’t make variables for an animal’s traits, because those traits don’t change (disregarding evolution). Firstly, you need a decent book on object-oriented design, rather than asking us to help. Take some initiative and do some research. For the moment, how about just implementing some basic polymorphic boolean functions like IsTerrestrial(), IsAquatic(), etc… Maybe … Read more

[Solved] Android | Java | check if in GPS Android i passed specific location [closed]

I think you can refer the Location API to calculate the distance between your current location and another one. http://developer.android.com/reference/android/location/Location.html I think you can one of these methods: public static void distanceBetween (double startLatitude, double startLongitude, double endLatitude, double endLongitude, float[] results) public float distanceTo (Location dest) 1 solved Android | Java | check if … Read more

[Solved] How can I check if an XML response contains a pattern? [closed]

In Groovy, you can use the following check (assuming text is the variable holding the string you provided in the question): if (text=~/Server returned HTTP response code: 503\b/){ println “503 code detected” } else { println “503 code not detected” } But it also seems you can just use contains: if (text.contains(‘HTTP response code: 503 … Read more

[Solved] Android Studio API 22 gives an error Unfortunately, “App Name” has stopped working after successful build [duplicate]

Try removing the android prefix in <item name=”android:windowNoTitle”>true</item> i.e replace it with <item name=”windowNoTitle”>true</item>. Also replace <style name=”MyMaterialTheme.Base” parent=”Theme.AppCompat.Light.DarkActionBar”> with <style name=”MyMaterialTheme.Base” parent=”Theme.AppCompat”> , the Light.DarkActionBar part is unnecessary as you are specifying windowActionbar as false and windowNoTitle as true and setting action bar in activity. Also one more thing, ActionBarActivity is deprecated in revision … Read more

[Solved] How to print a localized date with only month and day (no year) in Java? [closed]

The Java locale framework supports internationalization of some common forms of date / time, numbers, currency and so on. For date / time values the set of predefined formats is described in the Java Tutorial: Using Predefined Formats. Unfortunately, “year and month” is not one of the formats. This leaves you with only one option. … Read more

[Solved] Falling objects in java? [closed]

“but they all fall from the top of the screen where y=0” This coincides with your requirement (which you mention a few lines above) so this is fine. You just need to make the x value random. So keep y=0 as a constant, and just make the x random. Look at this class: Random Use … Read more

[Solved] I want to reduce the code in Android

Are all the buttons currently in the same class? Because if so, you can just make a method that does the work, and call it for each button, passing as method arguments any variables that change from button to button. If not, you can still make a method, but you’ll just have to make it … Read more

[Solved] How can i used nested while loop ? in java

In your outer while loop you need this: overtime = 0; if (hoursWorked>8) overtime = (hoursWorked-8)*(rateOfPay*1.5) – (hoursWorked-8)*rateOfPay; // Calculate OVERTIME HOURS sets the overtime to zero for each iteration, and you’ll have to subtract the normal rate for overtime hours (otherwise you add them twice) and then you’ll have to add the overtime to … Read more