Vinski's Profile
Reputation: 8
Worker
- Group:
- New Members
- Active Posts:
- 14 (0.05 per day)
- Joined:
- 29-September 12
- Profile Views:
- 216
- Last Active:
Oct 09 2012 12:49 PM- Currently:
- Offline
Previous Fields
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: Problem translating image processing algorithm into code
Posted 1 Oct 2012
You're welcome. -
In Topic: Problem translating image processing algorithm into code
Posted 1 Oct 2012
KirosXannon, on 01 October 2012 - 07:47 AM, said:I understand how to check for all of those instances, but it's different because I don't know the value of the variables beforehand. a,b,c and d are unknown. Suppose only two of them are not zero, how do I check that the two that are non-zero are equal to each other? Also suppose that there's only one that's not equal to zero, how do I say as well that this is also fine and nothing needs to be checked because it's the only one that's not zero?
First, make two integer arrays (which have 4 (<- number of variables) slots)) and then set first integer array's values to variables a, b, c and d. After that, make a for loop which scans through the array and if a number is not equal to zero, it puts the variable in the second array. When that is over, you scan through the second array and check if numbers are equal to each other. In code it would be something like this:
public static void main(String[] args) { int a = 0; int b = 7; int c = 0; int d = 9; int[] integers = {a, b, c, d}; int[] notZeros = new int[4]; for(int i = 0; i < integers.length; i++){ if(integers[i] != 0) notZeros[i] = integers[i]; } for(int i = 0; i < notZeros.length; i++){ int current = integers[i]; if(current == integers[0]){ if(i != 0){ // Your code. }else break; } if(current == integers[1]){ if(i != 1){ // Your code. }else break; } if(current == integers[2]){ if(i != 2){ // Your code. }else break; } if(current == integers[3]){ if(i != 3){ // Your code. }else break; } } }
Please excuse me. I've made a mistake there. This is the right way for the last for loop:
for(int i = 0; i < notZeros.length; i++){ int current = notZeros[i]; if(current == notZeros[0]){ if(i != 0){ // Your code. }else break; } if(current == notZeros[1]){ if(i != 1){ // Your code. }else break; } if(current == notZeros[2]){ if(i != 2){ // Your code. }else break; } if(current == notZeros[3]){ if(i != 3){ // Your code. }else break; } }
I'm so sorry, but I cannot edit my posts for some reason. I accidently put else break at the end of each if statement. This could also be done in an easier way. Argh, I failed a bit.
Anyway, just remove that else break;. -
In Topic: Problem translating image processing algorithm into code
Posted 1 Oct 2012
KirosXannon, on 01 October 2012 - 07:15 AM, said:...I really just need to know how to translate "if a,b,c and d are not equal to zero...
To check if a variable is not equal to zero, do this:
if(variable != 0){ // Your code here. }
KirosXannon, on 01 October 2012 - 07:15 AM, said:...and all non-zero values are equal to each other" into code...
To check if integer variables equal to integer variables, do this:
if(variable1 == variable2){ // Your code here. }
But, it's different with strings; Here is the way to do it with strings:
if(string1.equals(string2)){ // Your code here. } -
In Topic: Variable might not have been initialized
Posted 1 Oct 2012
Usually when that happens, you need to give value to the variable.
For example:
String whichDay = null;
-
In Topic: How do I Dispose a JFrame from another class?
Posted 30 Sep 2012
You could simply use two JPanels and then when you die, just switch them. That's kind of what I did on the game I'm currently developing since I don't want to use any libraries.
public synchronized void switchPanels(JPanel newPanel){ this.remove(panel); this.panel = newPanel; this.add(panel); this.setTitle(panel.getName()); // Delete this line if the name stays the same. this.validate(); // Very important line. Don't delete it. }(In order for this code to work, your class needs to extend JFrame.)
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
Contact Information
- E-mail:
- Private
Friends
|
|


Find Topics
Find Posts
View Reputation Given

|
Comments
Vinski has no profile comments yet. Why not say hello?