integer

0 is added but not shown as two digit when converted to int

Deadly 提交于 2020-01-05 07:10:11
问题 I want to add a 0 in front of a date if it is single digit. So I made a code: public class Zero { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String zero="0"; Calendar cal = new GregorianCalendar(); int day1 = cal.get(Calendar.DAY_OF_MONTH); String seven1=Integer.toString(day1); System.out.println(""+seven1); System.out.println(""+day1); String added=zero.concat(seven1); System.out.println(""+added); int change=Integer.parseInt(added);

Why can't iterrows do math - and instead returns integer values where these should be floats

 ̄綄美尐妖づ 提交于 2020-01-05 06:23:08
问题 I want to loop through a data frame and then fill a column of the frame with interest rates from a complex calculation. Apparently, the best way to loop through a frame is to use iterrows - But when I use iterrows , I get integer values only: import pandas df = pandas.DataFrame({"A": [1,2,3,4,5]}) df['B']=0 for index, row in df.iterrows(): row['B']=row['A']*10.05 df returns A B 0 1 10 1 2 20 2 3 30 3 4 40 4 5 50 Which is incorrect, given that all values in A were multiplied by 10.05. The

Finding a square root using only integers

好久不见. 提交于 2020-01-05 00:50:06
问题 Recently, I came across a problem in someone's programming class. It asked them to compute a square root using only integers; they were to use one integer to represent the part before the decimal point and another integer to represent the part after the decimal point. The problem said that using floating point numbers was not allowed. However, after thinking about it for some time, I can't seem to come up with a way of doing it without using floating point. I've Googled high and low and I can

REGEXP_SUBSTR converted output is not casting as integer

拜拜、爱过 提交于 2020-01-04 15:52:20
问题 I tried extracting all the digits out of a 20 character string by using REGEXP_SUBSTR Sql function like below. select REGEXP_SUBSTR(substring(mycolumn,1,20), '^[0-9]', 1) || REGEXP_SUBSTR(substring(mycolumn,1,20), '^[0-9]', 2) || REGEXP_SUBSTR(substring(mycolumn,1,20), '^[0-9]', 3) ... ... || REGEXP_SUBSTR(substring(mycolumn,1,20), '^[0-9]', 20) from tbl; But when trying to cast it as bigint / decimal or any numeric data type it is failing with Invalid input syntax for type numeric or Invalid

Integer promotion (MISRA C:2012 Rule 7.2)

不想你离开。 提交于 2020-01-04 05:32:28
问题 MISRA enforces the use of the U suffix for unsigned integer constants uint32_t the_answer = 0x42U; I feel the U is a bit boilerplate because the line is very understandable without it. So I am wondering how much this rule is important and if unsigned int x = 1 is truely a bad example of implicit integer promotion. 回答1: You are correct, the U in this specific example is superfluous as per an exception to Rule 10.3: "A non-negative integer constant expression of essentially signed type may be

Read 64 bit integer string from file

亡梦爱人 提交于 2020-01-04 05:06:15
问题 We have a file that has a 64 bit integer as a string in it. How do we scanf() or otherwise parse this numeric string into an unsigned 64 bit integer type in C++ ? We are aware of things like %lld etc., but a lot of ways to do this parse seem to break compiles under different compilers and stdlibs. The code should compile under gcc and the Microsoft C++ compiler (of course full compliance with standards would be a plus) 回答1: GCC has long long, as will compilers for C++0x. MSVC++ doesn't (yet),

Given an array of integers [x0 x1 x2], how do you calculate all possible permutations from [0 0 0] to [x0 x1 x2]?

拥有回忆 提交于 2020-01-03 17:28:20
问题 I am writing a program that takes in an ArrayList and I need to calculate all possible permutations starting with a list of zeroes, up to the value in the corresponding input list. Does anyone know how to iteratively calculate these values? For example, given [ 1 2 ] as input, it should find and store the following lists: [0 0], [1 0], [1 1], [1 2], [0 1], [0 2] Thanks! 回答1: Here's a standard recursive generator: import java.util.Arrays; //... static void generate(int... limits) { generate

boolean operations with integers [duplicate]

六眼飞鱼酱① 提交于 2020-01-03 17:17:22
问题 This question already has answers here : Closed 11 years ago . This is probably pretty basic... but I don't seem to get it: How does (2 & 1) = 0 (3 & 1) = 1 (4 & 1) = 0 etc.. This pattern above seems to help find even numbers or (0 | 1) = 1 (1 | 1) = 1 (2 | 1) = 3 (3 | 1) = 4 (4 | 1) = 5 (5 | 1) = 5 I know how boolean algebra works between bits. But I don't understand how Boolean algebra works with integers (in C# at the least). thanks in advance. 回答1: It works the same way in C# as it does

Last 2 digits of an integer? Python 3

半城伤御伤魂 提交于 2020-01-03 16:47:28
问题 With my code, I want to get the last two digits of an integer. But when I make x a positive number, it will take the first x digits, if it is a negative number, it will remove the first x digits. Code: number_of_numbers = 1 num = 9 while number_of_numbers <= 100: done = False num = num*10 num = num+1 while done == False: num_last = int(repr(num)[x]) if num_last%14 == 0: number_of_numbers = number_of_numbers + 1 done = True else: num = num + 1 print(num) 回答1: Why don't you extract the absolute

MySQL integer unsigned arithmetic problems?

折月煮酒 提交于 2020-01-03 16:44:20
问题 Does MySQL (5.0.45) like to do strange internal typecasts with unsigned maths? I am storing integers unsigned but when selecting basic arithmetic I get outrageous numbers: mysql> create table tt ( a integer unsigned , b integer unsigned , c float ); Query OK, 0 rows affected (0.41 sec) mysql> insert into tt values (215731,216774,1.58085); Query OK, 1 row affected (0.00 sec) mysql> select a,b,c from tt; +--------+--------+---------+ | a | b | c | +--------+--------+---------+ | 215731 | 216774