Skip to main content

Posts

Showing posts with the label int

Convert String to Int Objective-C?

Really basic iPhone Objective-C question. I'm trying to extract a string (which is really a int) from an array and then use it as an int in a function. I'm trying to convert it to a int using intValue. Here's the code I've been trying. NSArray *_returnedArguments = [serverOutput componentsSeparatedByString:@":"]; [_appDelegate loggedIn:usernameField.text:passwordField.text:(int)[[_returnedArguments objectAtIndex:2] intValue]]; I get the error passing argument 3 of 'loggedIn:::' makes pointer from integer without a cast Thanks for the help, Christian Stewart

Java code to find a particular number from a given list of numbers

How would you solve the following java problem? Write code that finds a particular number from a given list of numbers which are stored as strings? I assume you would have to convert the strings to ints or doubles, using double.parse double or int.parse int and then do some kind of binary search maybe? Here's what I have tried so far import java.io.*; import java.util.Scanner; public class FindNum { static int nElems; static String[] array; public static void main (String[] args) throws IOException { File testFile = new File("X:\\numbers.txt"); Scanner in = new Scanner(System.in); System.out.println("What number would you like to find?"); nElems = in.nextInt(); while(true){ System.out.println("Binary search"); array = new String[nElems]; getContents(testFile);//loads the file That's just basic input to get the access the file witht the list of numbers wondering how would I go about coding a binary se