[Solved] Bitwise shift operation choice

The reason it works this way is because C and C++ used << for left shift and >> for right shift long before Java. Those languages have both signed and unsigned types, and for signed types the sign bit was propagated in the right-shift case. Java does not have unsigned types, so they kept the … Read more

[Solved] How to check in Java whether the input Sentence is of palindrome(not exactly, but like that) in nature or not?

First take the words of str in an array. Then check whether the words in the forward order and the reverse order are same. String[] words = str.split(” “); //splits at spaces boolean flag = true; int i, last = words.length – 1; for(i = 0; i <= last/2; i++){ if(!words[i].equalsIgnoreCase(words[last – i])){ flag = … Read more

[Solved] Convert string to rubbish

If you want a function that will return the same garbage for the same input string, this would work fine. public String rubbish(String input) { String result = “”; long seed = 0; long size = 0; for(int i = 0; i < input.length(); i ++) { seed += input.charAt(i); } seed %= Long.MAX_VALUE; size … Read more

[Solved] Improve condition check

You can just combine all four conditions into one using logical operators. For example by using logical and && and logical or ||. It could then look like: if ((first && second) || (third && fourth)) { return true; } Or with all conditions substituted: if ((Obj.getSource().equals(“abc”) && Obj.getDest().equals(“bcd”)) || (Obj.getSource().equals(“abd”) && Obj.getDest().equals(“gdc”))) { return … Read more

[Solved] Finding the average [closed]

Since you only want the average of the HourlyEmp’s, you need to keep track of how many there are: double avg=0; int numHourlies = 0; //number of hourlyEmps you have found so far for(int i=0; i < Emp.length; i++) { if (Emp[i] instanceof HourlyEmp) { //just add up all the values for now … avg … Read more

[Solved] How should I declare strings? [duplicate]

You should not use == when comparing objects including strings. Generally == compares references, so it return true only of same objects. You should use equals() method instead: str1.equals(str2) It occasionally works for you in first case because java caches string constants, so “java” in both cases is represented by same instance of String. solved … Read more

[Solved] j2ee pattern for centralizing the process of looking up services [closed]

The service locator pattern can be used for looking up services as described in Core J2EE Patterns. Please notice that this pattern can be considered a bit “outdated” and arguably dependency injection should be preferred in most cases (see here for a more elaborate discussion). solved j2ee pattern for centralizing the process of looking up … Read more

[Solved] Error in program [closed]

It’s unclear what the problem is but your for loop doesnt over the letters in word as the termination condition is based on the empty List size passed to the buildAL method. Replace for (int i = 0; i < arr2.size(); i++) with for (int i = 0; i < word.length(); i++) { solved Error … Read more

[Solved] Simple Coding Problems

A solution: Scanner input = new Scanner(System.in); int l; // it should be int if read int l = input.nextInt(); if (l <= 30) { System.out.println(“40 Sinas”); } if (l > 30 && l < 50) { System.out.println(“55 Sinas”); } if (l > 50 && l < 100) { System.out.println(“70 Sinas”); } if (l >= … Read more

[Solved] the keyword “final” for BigDecimal.java [closed]

Immutable means, that class does not contain any method that would change it’s internal state. Example of immutable class: class ImmutableInteger { private final int value; public ImmutableInteger(int value) {this.value = value;} public int value() {return value;} public ImmutableInteger add(int a) { // instead of changing this state, we will create new instance with result … Read more

[Solved] How to save and update points in a share preferences

You need to convert the int to String using pointsAvailable.setText(“C”+String.valueOf(pointsAmount)); And to save the points, you need to store them in the SharedPreferences in onRewarded: saveCoins.edit().putInt(“C”,pointsAmount).commit() solved How to save and update points in a share preferences

[Solved] Java replace with regex [closed]

It is as simple as: “The Shawshank’s Redemption”.replaceAll(“\\S”, ” _”); We replace all non white-space characters \S with an underscore followed by a space. This would automatically make what is a space originally, 2 spaces. Note that a trailing space will be produced. 2 solved Java replace with regex [closed]

[Solved] how do i return the array from method?

To answer your question “How to return the matrix”: you are already doing it the right way. As you can see from the comments so far, the problem lies in the declaration of A. A is declared and initialized inside the for-loop: int [][]A = new int [size_num][size_num]; Hence its visibility is limited to the … Read more