[Solved] Static block + cannot find symbol [duplicate]

Your strBlock variable is a local variables within the static initializer block. Its scope is limited to that block, just like any other local variable. If you want to be able to access it in the main method, you’ll need to declare it as a field: static strBlock; // Static field declaration static { // … Read more

[Solved] issues with clone and for loop

As Andy Turner said for your first question : clone() is not being used. It just so happens that the variable is called clone, but that has no semantic importance to the code. Concerning the for statement he’s composed of 3 parts ,each separated by one ; , and none of them is obligated to … Read more

[Solved] HISTOGRAM (Array = Stars Output)

Every time you append the * in the builder object, clear the previous content. You can use stringBuilder.setLength(0); import javax.swing.*; public class Prop { public static void main(String args[]) { StringBuilder stringBuilder = new StringBuilder(); int n = 0; n = Integer.parseInt(JOptionPane.showInputDialog(“Enter value”)); int[] arr = new int[n]; String stars = “”; int input = … Read more

[Solved] Can I construct more than one type of object from same class data with the help of constructor in Java?

No, you can’t do that. The two constructors would have the same signature: MyClass(double, double, double). In order to distinguish the two, you’d have to give them different names, and you can’t do that with constructors. You can however create differently named static methods to use instead of constructors, e.g. public class MyClass { // … Read more

[Solved] Java hashing function to return int that does not exceed Integer.MAX_VALUE [closed]

1 The methods you used were for returning longs. The method you should use is String.hashCode() if you don’t need hashing for security purposes. Make sure to cast an integer as a String through String.valueOf(int) before hashing it, since you said you want to hash ints as well. int hash = String.valueOf(input).hashCode(); 2 Edit: Added … Read more

[Solved] Subtypes of Arrays

The JLS states that if B is assignable to A, then yes, B[] is assignable to A[]. This opens the door to serious implications though, demonstrated by this code: class A {} class B extends A {} class C extends A {} //… B[] bs = new B[2]; A[] as = bs; as[0] = new … Read more

[Solved] Replace second repeated word in string [closed]

Split the string by space and rename the last word. Then using the StringBuilder concatenate them together back to your original String. String str = “hello I am a example example” String[] parts = str.split(” “); parts[parts.length-1] = “moon”; System.out.println(parts[parts.length-1]); StringBuilder sb = new StringBuilder(); for (int i=0; i<parts.length; i++) { sb.append(parts[i]); sb.append(” “); } … Read more

[Solved] How to insert and display an image in Android? [closed]

Replace this line: Picasso.with(AddAdsActivity.this).load(image).placeholder(R.drawable.camera).into(TuitionImage); With this: Picasso.get().load(image).placeholder(R.drawable.camera).into(TuitionImage); And that’s it.. Your error will be solved. 2 solved How to insert and display an image in Android? [closed]

[Solved] Card layout parameters not working

You can try this as one of the solution if you do not want to specify the dimension for width and height of Image <?xml version=”1.0″ encoding=”utf-8″?> <android.support.v7.widget.CardView android:id=”@+id/cvAdvertFavourite” xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:card_view=”http://schemas.android.com/apk/res-auto” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:layout_marginTop=”2dip” android:layout_marginBottom=”2dip” card_view:cardUseCompatPadding=”true” > <LinearLayout android:layout_width=”match_parent” android:layout_height=”match_parent” android:orientation=”horizontal” android:padding=”8dp” > <ImageView android:id=”@+id/ivCardFavouriteAnimalPhoto” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_marginRight=”8dp” android:weight = “2”/> <RelativeLayout android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:weight … Read more

[Solved] Where do I define my variables? [closed]

you have to create an instance of your class in order to access non static variables from your static methods in java. public class MainGUI { int num1= 1366, num2= 528, num3= 482, sum; // declare these static? public static void main(String args[]) { MainGui m = new MainGUI(); sum = m.num1 + m.num2+ m.num3; … Read more