Yesterday a friend mine asked to help with her MS assignment, it is java so I got interested and solved it. But I was not satified with the logic which I provided, Is any other logic for this?
The aim is to print all possible 3 and 2 letter word from String "GOLD".
public class TestChars {
public static void main(String []args) {
String str = new String("abcdef");
char[] chara = str.toCharArray();
int count = 0;
int countForTwo = 0;
for(int i = 0; i < str.length(); i++) {
for(int j = 0 ; j < str.length(); j++){
if(i != j) {
System.out.println("" + chara[i] + chara[j]);
countForTwo++;
}
for(int k = 0; k < str.length(); k++) {
if( i != j && j != k && i != k) {
System.out.println("" + chara[i] + chara[j] + chara[k]);
count++;
}
}
}
}
System.out.println("" + count);
System.out.println("" + countForTwo);
}
}
BTW, Cricker match getting interested now, "Noxious Weed" really undesirable for Aussies.
Saturday, March 01, 2008
Subscribe to:
Post Comments (Atom)
From Generative AI to Agentic AI: 2 Weeks of Building MyNewsAI.io
From Generative to Agentic AI: 2 Weeks Building MyNewsAI.io Over the last two weeks, I set out to evolve MyNewsAI...
-
When I start thinking about future, my mind exploding without control, particularly current events and state of our economy. There is no d...
-
When I was young, i used to listen old stories from grandmother and a cousin of my grandfather. Most of the stories are from their flashback...
-
Already Microsoft getting heat from Google, that Google is capturing all critical functionalities from Microsoft office suite and developed ...
No comments:
Post a Comment