Posts

Showing posts with the label if-statement

Tic tac toe C++ overwriting the board

Tic tac toe C++ overwriting the board Hi so I have it set up the way I want to for the most part. The last part I'm trying to implement is to have it so the input does not overwrite itself when input either X or 0 . If someone could take a look at it and tell me what exactly I did wrong with my noRepeat function I would greatly appreciate it. Thanks. X 0 #include <iostream> using namespace std; const int ROWS = 3; const int COLS = 3; char Player1 = 'X'; char Player2 = 'O'; int row, col; char board[3][3]= { '*', '*', '*', '*', '*', '*', '*', '*', '*'}; //Game board //Prototypes void noRepeat(); void drawBoard(); void selection(int&, int&); char winner(); void switchPlayer(); int main() { cout << "Tic Tac Toe!" << endl << endl; drawBoard(); cout << endl << endl; while (1) { if ( noRepeat() ) { ...

Javascript “if” with “or” How check which will exec

Javascript “if” with “or” How check which will exec if (a != 1 || b != 2) { console.log(this, ' is required'); } Can we get the answer a is required or b is required ? a is required b is required Why not have two different ifs? – Mureinik Jul 1 at 17:56 You need to use multiple if statements. – Get Off My Lawn Jul 1 at 17:56 because I want check many parameter 10 or 20 - and i dont want 10 ifs – Alex Latro Jul 1 at 17:57 4 Answers 4 I am assuming this i...

Comparing Text Isn't Working in Java [duplicate]

Comparing Text Isn't Working in Java [duplicate] This question already has an answer here: So, I'm trying to do something really simple, and that's check if a password equals something in my SWT application. So, my code was this: if (passwordBox.getText() == "test") { passwordBox.setVisible(false); } However, in my application, which uses text fields marked as passwords (with that variable), it will not fire that when I click a button. I already have button handling working, since I have an else statement that fires, but this will not fire when the password box obviously equals "test". What's wrong here? else This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. Don't use "==" to compare strings. Instead use the equals(...) method. – camickr Jul 1 at 18:16 ...

I want to populate value in Dataframe based on matching values in other Dataframe

I want to populate value in Dataframe based on matching values in other Dataframe I am editing the question. I dont want to use groupby to use group values. I would appreciate if someone could help with just the query to transform data in the following way: I have one dataframe given as follows: df1: col1 col2 ------------ VG 12 G 11 A 10 P 06 VP 0 I want the new dataframe such as: df2: VG G A P VP --------------------- 12 11 10 06 0 I tried achieving this using if condition and I got following error: Code: if df1.Score=='VG': df2['VG']=df1.loc[df1['col1'] == 'VG', 'col2'] The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all() 3 Answers 3 agg and transform would work :) agg transform df.groupby('col1').agg(list).col2.transform(pd.Series).T.fillna(0) ...

Java8 enum avoid multiple if else

Java8 enum avoid multiple if else In java 8 is there any option to avoid multiple if else check with enum value and to execute particular operation. I dont like to use some thing like below example ? if enum equals A PRINT A else if enum equals B PRINT B else if enum equlas C PRINT C Is it possible you're looking for switch statements? – Silvio Mayolo Jul 1 at 17:37 You do not need to check the equality if the operation is always the same – Yassin Hajaj Jul 1 at 18:06 2 Answers 2 Define enum with abstract method and provide it's implementation with values. enum MyEnum{ A{ @Override...

How to check if an item in an ArrayList does not contain a certain word?

How to check if an item in an ArrayList<String> does not contain a certain word? I want to use a for loop like this: `button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Object.setList(); for(int i = 0; i < Object.getList.size(); i++) if(!Object.getList.get(i).trim().toLowerCase().contains("hello")) { Toast.makeText(getContext(), "List does not contain "Hello", Toast.LENGTH_LONG).show; } }` This is my model: public class Object { private ArrayList<String> mArrayList; public void setList() { mArrayList = new Arraylist<>(); mArrayList.add("Random Message"); mArrayList.add("ZZZZ") } public ArrayList<String> getList() { return mArrayList; } } I still keep getting the Toast message, but it works just fine when i use: if(!Object.getList().toString.trim().toLowerCase().contains("hello")) ...