[Solved] Java for every odd multiply of 90 [closed]

Your basic structure here should be pretty simple – just use a multiplier and an if statement with a modulus operator. For example (pseudo-code – check a tutorial if you can’t implement this idea): int multiplier=1; int maxMultiplier = 10; int value = 0; while (multiplier < maxMultiplier) { value = 90 * multiplier; if … Read more

[Solved] File handling comparing string with text file

Try this import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.Scanner; public class ReadFile { public static void main(String[] args) throws IOException { Scanner scanner = new Scanner(System.in); String classroom = scanner.nextLine().toLowerCase(); BufferedReader input = new BufferedReader(new FileReader(“data.txt”)); String data = input.readLine(); int subjectIndex = 10; String[] items = new String[0]; boolean match=false; while (data != … Read more

[Solved] Java new keyword

There is no benefit to packing as much as possible into a line of code. Separate it out as much as possible, make it easy to read. Strictly speaking, there is no need to call join() in this instance. The purpose of join is to make one thread wait for another thread to finish, but … Read more

[Solved] Why is my array still NULL

Thanks for the responses, I needed to assign the size of the array. public void stage1init() { stage1.stageW = 30; stage1.stageH = 30; stage1.tileSize = 100; stage1.stageStartX = 2; stage1.stageStartY = 24; stage1.TilePositionX = new double[stage1.stageW][stage1.stageH]; stage1.TilePositionY = new double[stage1.stageW][stage1.stageH]; //Layout Stage1 int W = stage1.stageH; int H = stage1.stageW; for(int i = 0; i … Read more

[Solved] Java generic wildcard function

class Super{ void superMethod(){} } class Sub extends Super{ void subMethod(){} } class Sub2 extends Super{ void subMethod2(){} } static <T extends Super> void processSuper(T input){ // this is safe and compiles input.superMethod(); // this doesn’t compile input.subMethod(); // nor this input.subMethod2(); } Look at the above code snippet. When we use an extends Bound, … Read more

[Solved] How to return current object by static method?

You would use a Static Factory public class Test{ private Test() { //Prevent construction by other classes, forcing the // use of the factory } public static Test create(){ return new Test(); } public static void main (String[] args){ Test ob = Test.create(); } } I’ve made a few changes to your example to show … Read more

[Solved] Creating Requests to an API in Java

Ok first open a gradle project and add these dependencies: implementation ‘com.google.code.gson:gson:2.8.5’ implementation ‘com.squareup.retrofit2:retrofit:2.4.0’ implementation ‘com.squareup.retrofit2:converter-gson:2.4.0’ Then make an interface for api calls: I have created a dummy for you: import retrofit2.Call; import retrofit2.http.GET; import retrofit2.http.Query; import java.util.List; public interface Api { @GET(“/state”) Call<List<String>> groupList(@Query(“id”) int groupId); } Then add another class for retrofitclient: import … Read more

[Solved] Syntax error on token “.”, @ expected after this token [duplicate]

When you do Type[] arr = { …, … }; that’s an array initializer. It can only be used in array declarations (or in array creation expressions, i.e. new String[]{“a”, “b”}). Arrays.asList is defined to take varargs arguments (asList(T… a)), so you do not have to wrap your arguments in an array first: Arrays.asList(“text”, “tek1”) … Read more

[Solved] Three joined tables query with many-to-many relationship in JPA [closed]

I think your SQL might look something like this: SELECT * FROM Hospital WHERE Postcode = 3000 AND Hospital_id IN (SELECT Hospital_id FROM Hospital_Medical hm INNER JOIN Medical_Service m ON hm.Medical_id = m.Medical_id where Medical_name=”Emergency”) AND Hospital_id IN (SELECT Hospital_id FROM Hospital_Language hl INNER JOIN Language_Service l ON hl.Language_id = l.Language_id where Language_name=”English”) solved Three … Read more

[Solved] what is wrong in my program ? i am trying to find the list of prime number from n to m

I have implemented it my way. Hope this helps. import java.util.Scanner; class PrimeNumbers { public static void main (String[] args) { Scanner scanner = new Scanner(System.in); int i =0; int num =0; //Empty String String primeNumbers = “”; System.out.println(“Enter the value of n:”); int n = scanner.nextInt(); System.out.println(“Enter the value of m:”); int m = … Read more

[Solved] Replace String variable with exact string

If I understand your question, you could use String.replace(CharSequence, CharSequence) like String str=”abcd”; String rep=”cd”; String nv = “kj”; str = str.replace(rep, nv); // <– old, new System.out.println(str); Output is (the requested) abkj 1 solved Replace String variable with exact string