if-statement

How check if array is full and if not full add to it?

£可爱£侵袭症+ 提交于 2019-12-24 18:33:23
问题 I've got array. I've got an isFull method, which checks if the array is full, but I don't know how to use this to check if it's full, then if it's not full add to the array, otherwise disregard the add call. The array should take 10 elements and then not accept any more. After 10 elements, it should 'be full' and disregard any addSpy calls. How would you implement this? public class ConcreteSubject extends AbstractSubject { public int arySize; private int i = 0; private static AbstractSpy[]

mysql if not exist

被刻印的时光 ゝ 提交于 2019-12-24 17:59:11
问题 I am coming from MSSQL, and now using Mysql, this may be a easy one but how do you execute a if not exist statement. thanks IF NOT EXISTS(SELECT * from users WHERE Username = spUsername) BEGIN INSERT into users(ID,Username,Password,Email,Birthdate,DateJoin) VALUES(UUID(),spUsername,spPassword,spEmail,spBirthDate,NOW()); END 回答1: Im not a database expert by any means but this is how I do it. http://www.somethinghitme.com/2010/05/06/mysql-stored-procedures-if-not-exists/ DECLARE SomeId int;

Alternatives to long if statement

扶醉桌前 提交于 2019-12-24 17:46:29
问题 I currently have a long if statement, which looks ugly, and I'm fairly certain isn't proper. It looks something like this. if self.folderactive.isChecked: folders.createDir('Desktop') elif not self.folderactive.isChecked: folders.deleteDir('Desktop') if self.folderactive_2.isChecked: folders.createDir('Documents') elif not self.folderactive_2.isChecked: folders.deleteDir('Documents') if self.folderactive_3.isChecked: folders.createDir('Downloads') elif not self.folderactive_3.isChecked:

Identify value in 1 column corresponding to equal values in two another columns by row

删除回忆录丶 提交于 2019-12-24 17:43:23
问题 I am sure that my question is quite simple but I couldn't figure out the solution. I want to check my table by rows. If two columns (V2, V3) have the same value in the same row I want to extract the value in the corresponding column V1 and add it to my table. Thus: my data m <- matrix(c(1,2,3,5,6,0,0,0,1,3,5,4,1,1,2), 5, 3) df1<-as.data.frame(m) > df1 V1 V2 V3 1 1 0 5 2 2 0 4 3 3 0 1 4 5 1 1 5 6 3 2 I want to compare V2 and V3. The same values (1,1) are in row 4, so I want to obtain value 5

Identify value in 1 column corresponding to equal values in two another columns by row

谁说我不能喝 提交于 2019-12-24 17:42:48
问题 I am sure that my question is quite simple but I couldn't figure out the solution. I want to check my table by rows. If two columns (V2, V3) have the same value in the same row I want to extract the value in the corresponding column V1 and add it to my table. Thus: my data m <- matrix(c(1,2,3,5,6,0,0,0,1,3,5,4,1,1,2), 5, 3) df1<-as.data.frame(m) > df1 V1 V2 V3 1 1 0 5 2 2 0 4 3 3 0 1 4 5 1 1 5 6 3 2 I want to compare V2 and V3. The same values (1,1) are in row 4, so I want to obtain value 5

VBA check for value in a range

我是研究僧i 提交于 2019-12-24 17:37:27
问题 I am trying to loop through a column and if cells = "what i'm lookng for" then do something. I have this so far, where I'm off is in the if statement where I check for the "name": Option Explicit Sub test() Dim wksDest As Worksheet Dim wksSource As Worksheet Dim rngSource As Range Dim name As String Dim LastRow As Long Dim LastCol As Long Dim c As Long Application.ScreenUpdating = False Set wksSource = Worksheets("Sheet1") With wksSource LastCol = .Cells(1, .Columns.Count).End(xlToLeft)

How do you check to see if the 1st letter in a string is equal to something?

。_饼干妹妹 提交于 2019-12-24 17:25:55
问题 In my if statement, I'm trying to check if the first letter of a string is either Y or y , and then proceed as such. Below is what I have, but I don't believe it to be correct. System.out.print("Do you wish to do another calculation (Yes/No): ") option = scan.next(); if (option.substring(0,1) == "N" && option.substring(0,1) == "n" ) { System.out.println("Have a good day"); System.exit(0); } bmi.setOption(option); I instantiated option as String option = " "; earlier on in my program. I know

Iterating through data frame and changing values on condition [R]

时光怂恿深爱的人放手 提交于 2019-12-24 17:17:44
问题 Had to make an account because this sequence of for loops has been annoying me for quite some time. I have a data frame in R with 1000 rows and 10 columns, with each value ranging from 1:3. I would like to re-code EVERY entry so that: 1==3, 2==2, 3==1. I understand that there are easier ways to do this, such as sub-setting each column and hard coding the condition, but this isn't always ideal as many of the data sets that I work with have up to 100 columns. I would like to use a nested loop

Conditional sum with output for all rows in r data.table

和自甴很熟 提交于 2019-12-24 17:13:21
问题 I have a coding issue what I think should be very easy. I have created a simplified dataset: DT <- data.table(Bank=rep(c("a","b","c"),4), Type=rep(c("Ass","Liab"),6), Amount=c(100,200,300,400,200,300,400,500,200,100,300,100)) # Bank Type Amount SumLiab # 1: a Ass 100 NA # 2: b Liab 200 700 # 3: c Ass 300 NA # 4: a Liab 400 500 # 5: b Ass 200 NA # 6: c Liab 300 400 # 7: a Ass 400 NA # 8: b Liab 500 700 # 9: c Ass 200 NA # 10: a Liab 100 500 # 11: b Ass 300 NA # 12: c Liab 100 400 I want to

2 pieces of similar PHP, one works one doesn't?

若如初见. 提交于 2019-12-24 16:44:13
问题 I've got a few fields on a property site, grabbing a value in English & depending on the value, translating it (if another language other than English is selected). This piece of code works fine: <?php if(get_post_meta($post->ID,'prop_parking',true) && $prop_parking): $prop_parking_meta = get_post_meta($post->ID,'prop_parking',true); if ($prop_parking_meta == 'Yes') { $prop_parking_meta = '<!--:en-->Yes<!--:--><!--:es-->Sí<!--:--><!--:ru-->да<!--:-->'; } elseif ($prop_parking_meta == 'No') {