GetDotted Domains

Viewing Thread:
"Java Woes"

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Thu 14/12/06 at 15:36
Regular
"Tornado Of Souls"
Posts: 5,680
Does anybody here know Java? I'm sure someone does.

Basically I'm trying to write a program to do my coursework for me.
It's to generate a huge truth table for some boolean logic or something. It wouldn't take *that* long to do by hand, but that's not the point. I take a Java class too so I thought it'd be good practice.

The basic idea is that I use a bunch of arrays to hold the information and then just pick in the format needed.

So I've written a method to populate the input variable (arrays) with 0s and 1s
[I plan to change it so it only has to be called once instead of one time per variable but I haven't thought about an alogrithm for that yet]

The relevent bits are:

private int[] s0,s1,i0,i1,i2,i3; //arrays for the input variables

public void populate(int n, int[] var) {
//n is number in an alternation.
//var is the input variable array to write into.
int total = (rows/n)/2;
for (int c = 0; c < total; c++) {
for (int i = 0; i < total; i++) {
for (int j = 0; j < n; j++) {
var[c] = 0;
}
for (int k = 0; k < n; k++) {
var[c] = 1;
}
}
}
}

Then I call this from main()...

TruthTable t1 = new TruthTable(64);
t1.populate(32, s0);

And it gives me some crap about static contexts:

[Mark@localhost Java Source]$ javac TruthTable.java
TruthTable.java:52: non-static variable s0 cannot be referenced from a static context
t1.populate(32, s0);
^
1 error


What am I doing wrong?



It killed my lovely neat indentation :(

And you'll have to excuse my hundereds of for loops, it wasn't really planned :p



----

Okay nevermind I got it :p
There have been no replies to this thread yet.
Thu 14/12/06 at 15:36
Regular
"Tornado Of Souls"
Posts: 5,680
Does anybody here know Java? I'm sure someone does.

Basically I'm trying to write a program to do my coursework for me.
It's to generate a huge truth table for some boolean logic or something. It wouldn't take *that* long to do by hand, but that's not the point. I take a Java class too so I thought it'd be good practice.

The basic idea is that I use a bunch of arrays to hold the information and then just pick in the format needed.

So I've written a method to populate the input variable (arrays) with 0s and 1s
[I plan to change it so it only has to be called once instead of one time per variable but I haven't thought about an alogrithm for that yet]

The relevent bits are:

private int[] s0,s1,i0,i1,i2,i3; //arrays for the input variables

public void populate(int n, int[] var) {
//n is number in an alternation.
//var is the input variable array to write into.
int total = (rows/n)/2;
for (int c = 0; c < total; c++) {
for (int i = 0; i < total; i++) {
for (int j = 0; j < n; j++) {
var[c] = 0;
}
for (int k = 0; k < n; k++) {
var[c] = 1;
}
}
}
}

Then I call this from main()...

TruthTable t1 = new TruthTable(64);
t1.populate(32, s0);

And it gives me some crap about static contexts:

[Mark@localhost Java Source]$ javac TruthTable.java
TruthTable.java:52: non-static variable s0 cannot be referenced from a static context
t1.populate(32, s0);
^
1 error


What am I doing wrong?



It killed my lovely neat indentation :(

And you'll have to excuse my hundereds of for loops, it wasn't really planned :p



----

Okay nevermind I got it :p

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

Very pleased
Very pleased with the help given by your staff. They explained technical details in an easy way and were patient when providing information to a non expert like me.
I've been with Freeola for 14 years...
I've been with Freeola for 14 years now, and in that time you have proven time and time again to be a top-ranking internet service provider and unbeatable hosting service. Thank you.
Anthony

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.