numbers

How to check if an integer includes a certain number in c#

家住魔仙堡 提交于 2019-12-04 07:16:05
问题 Is there a way I can check Integers if they contain a certain number in C#? For example: I want to check for 7. When I enter 17, the code will return 1. When I enter 28, the code will return 0. Thank You 回答1: int number = 17; int digit = 7; bool result = number.ToString().Contains(digit.ToString()); 回答2: Convert it to a string, then use String.Contains : int i = 17; int j = 28 int k = 7; bool a = i.ToString().Contains(k.ToString()); bool b = j.ToString().Contains(k.ToString()); 来源: https:/

How do i convert a string of ascii values to there original character/number in python

前提是你 提交于 2019-12-04 07:06:27
问题 i have a string with numbers that i previously converted with my encoder but now i am trying to decode it ive searched around and no answers seem to work if you have any i dear how to do this then let me know string = 91 39 65 97 66 98 67 99 32 49 50 51 39 93 outcome = ABCabc 123 回答1: outcome = "".join([your_decoder.decode(x) for x in string.split(" ")]) 来源: https://stackoverflow.com/questions/34899602/how-do-i-convert-a-string-of-ascii-values-to-there-original-character-number-in

Why my code for checking if a number is a palindrom won't work?

不打扰是莪最后的温柔 提交于 2019-12-04 07:00:01
问题 My Java code is here: import java.util.Scanner; public class task2 { public static void main(String args[]) { System.out.print("Input a 3 digit int"); Scanner scan = new Scanner(System.in); int x = scan.nextInt(); int isPalindrome = 0; while (x != 0) { isPalindrome = isPalindrome*10 + x % 10; x /= 10; } { if (x == isPalindrome){ System.out.print ("Yes, this is a palindrome!"); } else { System.out.print("No, try again"); } } } } The code will only recognize a palindrome if the numbers entered

Calculating 2^N in C# with long data type where N is 1929439432949324 [closed]

这一生的挚爱 提交于 2019-12-04 06:59:49
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 3 months ago . Currently I need to calculate 2^N , however N can be as large as 1929238932899 and I'm stuck using a long data type which can't hold a number that large. I've currently tried converting to 'BigInt' however I'm still stuck with the long data type restriction from what I've seen as well. I have a

Python, prime number checker [duplicate]

烈酒焚心 提交于 2019-12-04 06:41:05
问题 This question already has answers here : Simple Prime Generator in Python (23 answers) Closed 6 years ago . Hi i'm making a function that checks if a number is a prime or not but its telling me that 9 is a prime. def eprimo(num): if num < 2: return False if num == 2: return True else: for div in range(2,num): if num % div == 0: return False else: return True 回答1: You're going to return from the first iteration of that for loop whether you're done checking or not. You shouldn't return from

Is there a way in Objective-C to take a number and spell it out?

眉间皱痕 提交于 2019-12-04 06:40:03
I'm looking for a way to take a number (say 5 or 207), spell it out, and returns its ordinal form as a string (five or two hundred seven). All I could find was code that takes a number and returns its ordinal suffix (st, nd, rd, th) and the parts of English grammar guides that say you should spell out ordinals. I'm looking for a way to get a spelled out number with its ordinal suffix (fifth or two hundred seventh). evotopid Update : I came across this answer today, suggesting the use of the use of t his library under the MIT-License which also supports a few other languages. Hope this helps

Java program that prints out numbers that are divisible by other numbers

有些话、适合烂在心里 提交于 2019-12-04 06:27:02
问题 I have a program that reads two real numbers and then it prints out all the numbers between these two, that are divisible by 2 or 3 or 5. The program works fine, but when a user enters two really large numbers (for example, 1122222123333 and 214123324434434) the program takes a very long time to calculate the result. I would like to somehow fix the program, so that even for large numbers the result would be printed out instantly. here is my code so far : import java.util.Scanner; public class

Use HUGE numbers in apple Swift

≡放荡痞女 提交于 2019-12-04 06:25:38
问题 I'm not a programmer, I just like to write some code in my free time! I used to program in python3, now I'm trying to learn apple's Swift. My problem: in python3 I used without problems really huge numbers like 10**1000, I can print them, do math operations with them, and so on. In Swift, I can not do the same, because starting from 10**300 or 10**400, both Double and Float type gives "+infinity" as result, so I can not print it, nor do any operation with it... How can I solve this? (PS. If

How do you restart a python guess a number game?

耗尽温柔 提交于 2019-12-04 06:24:40
问题 I'm a newbie at python, so i couldn't figure out how to make this code repeat at the beginning again. Here is my code: import random guessesTaken = 0 print('Hello! What is your name?') myName = input() number = random.randint(1, 20) print('Well, ' + myName + ', I am thinking of a number between 1 and 20.') while guessesTaken < 5: print('Take a guess.') guess = input() guess = int(guess) guessesTaken = guessesTaken + 1 if guess < number: print('Your guess is too low.') if guess > number: print

Python - find integer closest to 0 in list [duplicate]

◇◆丶佛笑我妖孽 提交于 2019-12-04 06:11:19
Possible Duplicate: finding index of an item closest to the value in a list that's not entirely sorted I've got a list of positive and negative numbers in Python ( [237, 72, -18, 237, 236, 237, 60, -158, -273, -78, 492, 243] ). I want to find the number which is closest to 0. How do I do this? Óscar López How about this: lst = [237, 72, -18, 237, 236, 237, 60, -158, -273, -78, 492, 243] min((abs(x), x) for x in lst)[1] A nice and much shorter answer: min(lst, key=abs) verdesmarald reduce(lambda x, y : x if abs(y) > abs(x) else y, your_sequence) 来源: https://stackoverflow.com/questions/11923657