int

UITextField to Int to UILabel

北战南征 提交于 2019-12-20 07:39:27
问题 I'm used to C# and java, swift is definitely a different beast! I've been struggling for hours trying to get this to work. It is something so simple as well! I just want to get the text from a UITextField and turn it into an Int and then send the Int to a UILabel!! So many answers on the internet haven't worked at all! This is the error i'm getting now. ( using Xcode 8.2.1 and Swift 3.0.2 ) import UIKit class ViewController: UIViewController { @IBOutlet weak var firstTextField: UITextField!

string cannot be converted to int! how to sum a scanned int on java?

非 Y 不嫁゛ 提交于 2019-12-20 07:38:13
问题 I wrote this simple program to sum a scanned int written by the user, but when i compile it, it says that "string cannot be converted to int." What is wrong in this program? import java.util.*; public class Pr6{ public static void main(String[] args){ Scanner scan = new Scanner (System.in); int num1; int num2; int num3; int sum; System.out.print("Please write an integer: "); num1 = scan.nextLine(); System.out.print("Please write an integer: "); num2 = scan.nextLine(); System.out.print("Please

Using charAt method, won't add them as an Int, and wont print as string. Will explain better

大城市里の小女人 提交于 2019-12-20 07:17:40
问题 Alright, so here is my code: import java.util.Scanner; public class CarRental { public static String model; public static int letternum; public static String plate; public static String letter; public static int total; public static String alphabet = "abcdefghijklmnopqrstuvwxyz"; public static void main(String[] args) { Scanner input = new Scanner(System.in); //System.out.println("Car Model:"); //model = input.nextLine(); System.out.println("License Plate: "); plate = input.nextLine(); char

c++ converting string to int

守給你的承諾、 提交于 2019-12-20 06:38:11
问题 //sLine is the string for(int l = 0; l < sLine.length(); l++) { string sNumber; if(sLine[l] == '-') { sNumber.push_back(sLine[l]); sNumber.push_back(sLine[l + 1]); l++; } else if(sLine[l] != '\t') { sNumber.push_back(sLine[l]); } const char* testing = sNumber.c_str(); int num = atoi(testing); cout << num; } I have this for-loop which checks each character of the string and converts every number in this string to be a int. But for some reason, the atoi function is doing it twice so when I cout

Java String to complete mathematical sum

一世执手 提交于 2019-12-20 06:29:25
问题 In java, I am currently in the process of trying to find a way to do mathematical sums by typing in text to a JTextField, putting it into a String, and converting it to an int and solving. The problem is however, I don't want to simply put a number into the string but an actual sum including addition, subtraction etc. Currently it will accept just doing something like, 1 which will go from string and convert to an int, but when I do '1+1' or even just '1+' it throws exceptions everywhere

Strings, ints, and operators in Python

前提是你 提交于 2019-12-20 05:45:41
问题 How can I use an arithmetic operator (input by the user as a string) in an operation? I can print the operation itself, but I want to print the solution! Here's my clumsy attempt: # Initialise variables x = 2 y = 3 # Prompt the user for an arithmetic operator operator = input("Please enter *, /, +, or - : ") # Calculate the operation result = (str(x) + operator + str(y)) # Display the result print(result) 回答1: Use the operator module, which has functions that perform the same operations as

Swift 4 codable: the keys are Int array in JSON data

天大地大妈咪最大 提交于 2019-12-20 05:44:21
问题 { "0": { "name": "legaldoc.pdf", "cmisid": "yib5C-w92PPtxTBlXl4UJ8oDBthDtAU9mKN5kh2_KrQ" }, "1": { "name": "persdoc.pdf", "cmisid": "dqAnrdNMXGTz1RbOMI37OY6tH9xMdxiTnz6wEl2m-VE" }, "2": { "name": "certdoc.pdf", "cmisid": "6d7DuhldQlnb0JSjXlZb9mMOjxV3E_ID-ynJ0QRPMOA" } } How do I use Swift 4 Codable to parse JSON data like that? the problem is that the keys are Int array. How do I set CodingKeys for this? 回答1: As mentioned in the comments there is no array. All collection types are

Order by a field (int). If the field it is not int?

房东的猫 提交于 2019-12-20 05:25:05
问题 I have a problem with LINQ (in C#). I need to order a list of records by a field, which should be int , but sometimes not : from MyObject obj in new MyObject() where obj.Visibile=="1" orderby Int32.Parse(obj.Order) ascending select obj; and, as I said, if obj.Order is it not int , I get an error : System.FormatException: Input string was not in a correct format. I'd like to put the non-int items at the end of the list, without get any error . Is it possible? 回答1: Try by maming use of TryParse

Is there a way to take a series of zeros as an int input? [duplicate]

…衆ロ難τιáo~ 提交于 2019-12-20 05:23:17
问题 This question already has answers here : Find the reverse of a number (ex : 2500 reverse 0025) without the help of string or character (4 answers) Closed 4 years ago . I'm in the process of recreating the old mastermind video game from the '70s. The users makes a four digit guess, which is then logged as a vector. I know there exists a way to accept the input as a string, however I would find it odd if there isn't a way to do this with one single int input -- which I haven't been able to find

Convert String to Int with Stringstream

寵の児 提交于 2019-12-20 05:11:32
问题 have a little problem here: int IntegerTransformer::transformFrom(std::string string){ stream->clear(); std::cout<<string<<std::endl;; (*stream)<<string; int i; (*stream)>>i; std::cout<<i<<std::endl; return i; } I by calling this function with the string "67" (other values dont work too) i get this output: 67 6767 回答1: Did you notice there are two std::cout in the function itself? Beside that also add this: stream->str(""); //This ensures that the stream is empty before you use it. (*stream)<