Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
General Tech Bugs & Fixes 2 years ago
Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Turn Your Knowledge into Earnings.
Okay, so, I am working on porting an IM client over from autoit to java, and I'm still rather new to java.
What I am attempting to do is create a 2d array where I can store every user's conversation history in the array next to their name.
Then what I want to do, is, on demand, write this chat history into an edit control, by providing the user's username, thus showing the chat history with that user on screen when asked.
Tried several variations of code.
Array functions:
public class conversations { public static String[][] conversationspool = new String[100][]; public static String[][] init() { for (int i = 0; i < 99; i++) { conversations.conversationspool[i] = new String[2]; } return conversations.conversationspool; } public static String startConvo(String user) { for (int start = 0; start < 99; start++) { if (conversations.conversationspool[start][0] == user) { return conversations.conversationspool[start][1]; } } for (int start = 0; start < 99; start++) { if (conversations.conversationspool[start][0] == "") { conversations.conversationspool[start][0] = user; conversations.conversationspool[start][1] = "<center>Conversation with " + user + "center>"; System.out.print(conversations.conversationspool[start][1]); return conversations.conversationspool[start][1]; } } return "0"; } public static String addToConvo(String user, String html) { for (int start = 0; start < 99; start++) { if (conversations.conversationspool[start][0] == user) { conversations REPLY 0 views 0 likes 0 shares Facebook Twitter Linked In WhatsApp
Upon reaching return, the method stops executing.
return
//... //array == {"no","no","yes","no","","yes",...} for (int i = 0; i < 99; i++){ if (array[i].equals("yes")){ // do something return something; } } // this will stop at i == 2 and will not reach the end of for loop
This would explain why you would get only first encounter from the array. I assume you want all the pieces of the conversation.
I assume the init() method adds data to the variable. In the code you provided, it doesn't add anything to the array so it is empty. This is why the conditions are never met and string "0" is returned. Also, the function of init() could have been done in the first line:
init()
public static String[][] conversationspool = new String[100][2];
== not the same as .equals() Comparing strings in java
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
General Tech 9 Answers
General Tech 7 Answers
General Tech 3 Answers
General Tech 2 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.