How do I break the infinite loop? - Java [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 days ago.
Improve this question
This chunk of my Java code keeps returning an infinite loop. How do I change the code to break the infinite loop?
public void setResult(int result) {
this.result = result;
equasion(result);
}
public void equasion(int number) {
setResult(number * number);
}

Related

How to rught a loop that delete elents of collection,which creat arifmetick progression [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 days ago.
Improve this question
How to write a loop that will delete those elements of the collection whose numbers form an arithmetic progression, by type if the number 246 deletes, but the second 245 does not, since it does not oblige the progression
import java.util.ArrayList;
public class n {
public static void main(String[] args) {
ArrayList nums = new ArrayList<>();
nums.add(24);
nums.add(223);
nums.add(2424);
nums.add(135);
nums.add(258);
nums.add(246);
for (int i = 0; i < nums.size();i++){
if
}
}
}

How to convert to "filter" from for loop [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 months ago.
Improve this question
I have a simple for loop
and I want to change it into a statement using filter
for (int lotto_num: lottos) {
if (lotto_num == 0) {
unknown_count++;
}
for (int win_num : win_nums) {
if (lotto_num == win_num) {
count ++;
}
}
}
is it possible? I dont't really know how to use filter and stream.
In order to use Java's Stram API you should firstly convert your int[] arrays win_nums and lottos to List<Integer>.
It can be done this way:
List<Integer> win_nums_list = IntStream.of(win_nums).boxed().collect(Collectors.toList());
List<Integer> lottos_list= IntStream.of(lottos).boxed().collect(Collectors.toList());
Now we can use Stream API to get the desired result.
int count = win_nums_list.stream().filter(win_num -> lottos_list.contains(win_num)).count();
int unknown_count = lottos_list.stream().filter(lotto -> lotto== 0).count();
with adding imports to the beginning of your code:
import java.util.*;

cannot resolved method 'putExtra(java.lang.String, java.util.List<java.lang.String>) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
itemView.setOnClickListener(new View.OnClickListener() {/da
#Override//s
public void onClick(View view) {
Intent postDetailActivity = new Intent(mContext, PostDetailActivity.class); //s
int position = getAdapterPosition();
postDetailActivity.putExtra("fname",mData.get(position).getPRFCOACHFNAME());
postDetailActivity.putExtra("lname",mData.get(position).getPRFCOACHLNAME());
postDetailActivity.putExtra("expertise",mData.get(position).getPRFCOACHSPECIALIZATION()); // this is where the problem
postDetailActivity.putExtra("skill",mData.get(position).getPRFCOACHSKILL());
postDetailActivity.putExtra("technique",mData.get(position).getPRFCOACHTECHNIQUE());
postDetailActivity.putExtra("control",mData.get(position).getPRFCOACHCONTROL());
postDetailActivity.putExtra("management",mData.get(position).getPRFCOACHMANAGEMENT());
mContext.startActivity(postDetailActivity);
}
});//sa
//sadsada
The getPRFCOACHSPECIALIZATION error, cannot resolved
To pass a List<String>, you need to use putStringArrayListExtra.
Instead of using
postDetailActivity.putExtra("expertise",mData.get(position).getPRFCOACHSPECIALIZATION());
Use
postDetailActivity.putStringArrayListExtra("expertise",mData.get(position).getPRFCOACHSPECIALIZATION());

Multiples of 20 in java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I done a coding to get the output 20,40,60,80 and 100.
Multiple.java:
public class Multiple {
static int n=20;
static int m;
public static void main(String[] args) {
for(int i=1;i<=5;i++){
m=n*i;
System.out.println(m);
}
}
}
Output:
20
40
60
80
100
I didn't have any issue in this coding.I got an output successfully.But loop running 5 times.Let me know is there any other way to get these output(20,40,60,80 and 100) in simplest way.
very interesting. if you know the output result (it's fixed), why don't you write them out directly:
System.out.println(20);
System.out.println(40);
System.out.println(60);
System.out.println(80);
System.out.println(100);`
oh i see, you think that's too long. Then probably you can use the below:
int a = 0;
while(a<100){ a += 20; System.out.println(a);}
Enjoy it!

using objects names (like panels) from an array of strings [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am trying to run some objects methods in this way:
String[] sequencer = {"seq1", "seq2", "seq3", "seq4", "seq5", "seq6", "seq7", "seq8"};
for(int i; i<9; i++) {
sequencer[i].setBackground(Color.red);
}
seq1, seq2..seq8 are jPanels. Any idea how to do this ? I hope you understand what I want to do.
Can you do this? Or are you looking for something else?
JPanel [] sequencer = new JPanel[]{seq1, seq2, seq3, seq4, seq, seq6, seq7, seq8};
for(int i; i<9; i++) {
sequencer [i].setBackground(Color.red);
}

Categories