Following the algorithm on wikipedia, I created a next_permutation function for C#. You have my permission to use it for anything (such as work, personal, or school projects) unless, of course, you are being directly tested on creating such a function (such as a school quiz, test, or homework assignment) in which case you do not have my permission to use it in any way.
/* * Transitions perm to the next lexigraphical permutation and * returns true, unless it is the last permutation, in which case * it resets to the first permutation and returns false */ static public bool next_permutation(int[] perm) { int n = perm.Length; int k = -1; for (int i = 1; i < n; i++) if (perm[i - 1] < perm[i]) k = i - 1; if (k == -1) { for (int i = 0; i < n; i++) perm[i] = i; return false; } int l = k + 1; for (int i = l; i < n; i++) if (perm[k] < perm[i]) l = i; int t = perm[k]; perm[k] = perm[l]; perm[l] = t; Array.Reverse(perm, k + 1, perm.Length - (k + 1)); return true; }
Using the “algorithm” package, add the following LaTeX code anywhere in your document before your algorithms:
I made these tutorials because I wasn’t aware of any good (i.e. simple, clear, and concise) Java programming tutorials online. But recently I’ve been introduced to a couple of good resources, so I’m not going to make any more tutorials.
http://www.cs.princeton.edu/introcs/10elements/
Read sections 1 through 4, skipping the “Case Study” of each section.
Good luck with your programming!
These are the most important variables:
Give it a try!
Your program might look something like this:
public class Program {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int age = 5;
double cost = 2.89; // Gas prices in northern Utah
char middleInitial = ‘Z’;
boolean hungry = false;
boolean male;
age = 20;
hungry = true;
male = hungry;
System.out.println(“Hello World!”);
System.out.println(age);
System.out.println(cost);
System.out.println(middleInitial);
System.out.println(hungry);
System.out.println(male);
}
}
Run your program and notice the output in the console.
The file that you created in the previous tutorial should look like this:
public class Program {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
THE BIG PICTURE – As you can see, we have a class (called “Program”) containing one function (called “main”) that does absolutely nothing. Our first task will be to make the program display text to the user. To do that, write the following somewhere between the main function’s “{” and “}” markers:
System.out.println(“Hello World!”);
This command runs another function called “System.out.println”. When running another function, everything inside of the parenthesis is sent as information to that function. All text messages (called “Strings”) must be surrounded in quotation marks. Finally, all commands end with a semi-colon.
You’re final program should look like this:
public class Program {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(“Hello World!”);
}
}
Run your program by clicking on the “Run” menu and selecting “Run” or “Run Last Launched.” Notice, in the “Console” tab, that the message “Hello World!” was displayed!
Every program that you make needs to be in a new “Project.”
Congratulations, you made a project for your first program! Now you need to create a file to write your Java code in.
Now you’re ready to start programming!
These instructions will lead you through the process of installing tools needed in order to program in Java on a Windows computer.
http://www.oracle.com/technetwork/java/javase/downloads/index.html
http://www.eclipse.org/downloads/
Then unzip the file to some directory (say, “C:\Program Files” – it should create a subdirectory called “eclipse”)
Cliff Stoll’s love, Martha, addressed his ethical concerns as he tracked down a hacker in his book, “The Cuckoo’s Egg.” Most people value privacy. Martha personally wouldn’t care to invade anyone’s privacy, but she encouraged Cliff to compromise the privacy of several users when it allowed him to find one hacker. She minimized concern for punishment by saying, “the worst it would be is invasion of privacy … so I don’t see why you can’t” (Stoll 23). Later, she suggested that – depending on the circumstances – the hacker might even be the “good guy.” The ethical implications of Cliff’s attempts are challenged as she says, “maybe this hacker is closer to us politically than those security people. What if you’re chasing someone on your own side?” (Stoll 82). Loyalty and the importance of privacy are two of the ethical issues addressed by Martha.
Loyalty to one side also means commitment in fighting the opposition. If the hacker shared the same political agendas with Cliff, and was hoping to improve the world through such hacking attempts, then it would relatively be ethically right for Cliff to support the hacker. Being in favor of the U.S. government, however, it was Cliff’s ethical responsibility to fight the hacker.
Sometimes it would be too difficult, or impossible, to enforce a law without invading privacy. In this situation, the privacy of several users was compromised at the cost of watching a hacker. If everyone was legally allowed to watch what anyone else was doing at any time, then there would be no assurance of privacy. However, it’s important that some law enforcers are permitted to breach privacy, on certain grounds, for detective work to progress. To keep individual privacy, citizens should be punished for invading the privacy of others unless such law enforcers refuse to take action. In Cliff’s situation, he is justified in watching the activity of all users, and in tracing phone calls, because the FBI wouldn’t look into the case themselves.
Eventually, even if it takes a while, decisions that affect most or all of a population, will settle on what the majority prefers. When the majority of the Nephites were opposed to God, they chose to govern contrary to His commandments – selfishly engaging in war, and creating allies that promoted dishonesty (with the Gadianton robber’s, for example). When the majority of the city of Enoch favored God, they lived the law of consecration. “Flattening” the world, as described by Thomas L. Friedman in his book, “The World is Flat,” is preferable to the current majority of humankind because it seems to empower us to live more comfortably, to be able to get more accomplished in life, and to profit more than we could have in the past. The world is flattening because the majority of humankind wants it to.
Not only is the world flattening, but it’s getting smaller too. With Google Earth, I can visit Paris without leaving my bedroom. I can also drive around my own street, and see the apartment complex that I live in, using Google’s Street View. I don’t feel so far from my parents, who live 700 miles away, because I can hear their voices over the phone. I almost felt like I was able to visit my friend, in person, who lives 1,800 miles away, as I talked to her with my WebCam. Not all, but some of the same forces that are flattening the world, are making it smaller at the same time.
As the world is getting flatter and smaller, individuals are becoming more alike. Flattening applies to job opportunities and information availability, sure, but also to cultural diversity. British bands are finding fans in America, and American bands are becoming popular in Asia. Clothing fashions are being shared among nations. Core values, within a culture, will define the rate and direction that the culture allows itself to change. But in all, cultures are combining into one.
As I am getting older, I am beginning to hear more, specific, rules to making computer use a safe experience. I hear these rules and I think, “that’s right! How could anyone ever be safe without living that rule? I don’t remember MY parents giving me that rule.” That’s because the potential dangerous of computer use is increasing – for at least two reasons. Offenses are increasing as the number of Internet users is increasing and predators are becoming smarter. Our defense is decreasing as we are becoming more comfortable with the Internet – “letting down our guard.” Other than imprisoning predators, there is little that we can do to decrease the offensive side of Internet use. We can, however, personally improve our defense by learning and following Internet safety rules.