Search Results

Search found 31321 results on 1253 pages for 'array size'.

Page 36/1253 | < Previous Page | 32 33 34 35 36 37 38 39 40 41 42 43  | Next Page >

  • java: Read text file and store the info in an array using scanner class

    - by Amateur
    Hi, I have a text file include Student Grades like Kim $ 40 $ 45 Jack $ 35 $ 40 I'm trying to read this data from the text file and store the information into an array list using Scanner Class could any one guied me to write the code correctly ? Here is what I have so far public class ReadStudentsGrade { public static void main(String[] args) throws IOException { ArrayList stuRec = new ArrayList(); File file = new File("c:\\StudentGrade.txt"); try { Scanner scanner = new Scanner(file).useDelimiter("$"); while (scanner.hasNextLine()) { String stuName = scanner.nextLine(); int midTirmGrade = scanner.nextInt(); int finalGrade = scanner.nextInt(); System.out.println(stuName + " " + midTirmGrade + " " + finalGrade); } } catch (FileNotFoundException e) { e.printStackTrace(); } }

    Read the article

  • PHP: testing for existence of a cell in a multidimensional array

    - by gidireich
    Hi, I have an array with numerous dimensions. Want to test for existence of a cell. The below cascaded approach, will be for sure a safe way to do it: if (array_key_exists($arr, 'dim1Key')) if (array_key_exists($arr['dim1Key'], 'dim2Key')) if (array_key_exists($arr['dim1Key']['dim2Key'], 'dim3Key')) echo "cell exists"; But it there a simpler way? I'll go into more details about this: 1. Can I perform this check in one single statement? 2. Do I have to use array_key_exist or can I use something like isset? Will appreciate if someone explains when to use each and why Thanks Gidi

    Read the article

  • Array of pointers in objective-c

    - by Justin
    I'm getting confused by pointers in objective-c. Basically I have a bunch of static data in my code. static int dataSet0[2][2] = {{0, 1}, {2, 3}}; static int dataSet1[2][2] = {{4, 5}, {6, 7}}; And I want to have an array to index it all. dataSets[0]; //Would give me dataSet0... What should the type of dataSets be, and how would I initialize it?

    Read the article

  • how to build an accumulator array in matlab

    - by schwiz
    I'm very new to matlab so sorry if this is a dumb question. I have to following matrices: im = imread('image.jpg'); %<370x366 double> [y,x] = find(im); %x & y both <1280x1 double> theta; %<370x366 double> computed from gradient of image I can currently plot points one at a time like this: plot(x(502) + 120*cos(theta(y(502),x(502))),y(502) + 120*sin(theta(y(502),x(502))),'*b'); But what I want to do is some how increment an accumulator array, something like this: acc = zeros(size(im)); acc(y,x) = acc(x + 120*cos(theta(y,x)),y + 120*sin(theta(y,x)),'*b')) + 1; It would be nice if the 120 could actually be another matrix containing different radius values as well.

    Read the article

  • Can't make an array in C#

    - by Josh
    I'm trying to make a dynamic array in C# but I get an annoying error message. Here's my code: private void Form1_Load(object sender, EventArgs e) { int[] dataArray; Random random = new Random(); for (int i = 0; i < random.Next(1, 10); i++) { dataArray[i] = random.Next(1, 1000); } } And the error: Use of unassigned local variable 'dataArray' This is just baffling my mind. I came from VB, so please me gentle, lol. Cheers.

    Read the article

  • mutidimensional array from javascript/jquery to ruby/sinatra

    - by user199368
    Hi, how do I pass a 2-dimensional array from javascript to ruby, please? I have this on client side: function send_data() { var testdata = { "1": { "name": "client_1", "note": "bigboy" }, "2": { "name": "client_2", "note": "smallboy" } } console.log(testdata); $.ajax({ type: 'POST', url: 'test', dataType: 'json', data: testdata }); } and this on server side: post '/test' do p params end but I can't get it right. The best I could get on server side is something like {"1"=>"[object Object]", "2"=>"[object Object]"} I tried to add JSON.stringify on client side and JSON.parse on server side, but the first resulted in {"{\"1\":{\"name\":\"client_1\",\"note\":\"bigboy\"},\"2\":{\"name\":\"client_2\",\"note\":\"smallboy\"}}"=>nil} while the latter has thrown a TypeError - can't convert Hash into String. Could anyone help, or maybe post a short snippet of correct code, please? Thank you

    Read the article

  • Ruby - Call method passing values of array as each parameter

    - by Markus Orreilly
    I'm currently stuck on this problem. I've hooked into the method_missing function in a class I've made. When a function is called that doesn't exist, I want to call another function I know exists, passing the args array as all of the parameters to the second function. Does anyone know a way to do this? For example, I'd like to do something like this: class Blah def valid_method(p1, p2, p3, opt=false) puts "p1: #{p1}, p2: #{p2}, p3: #{p3}, opt: #{opt.inspect}" end def method_missing(methodname, *args) if methodname.to_s =~ /_with_opt$/ real_method = methodname.to_s.gsub(/_with_opt$/, '') send(real_method, args) # <-- this is the problem end end end b = Blah.new b.valid_method(1,2,3) # output: p1: 1, p2: 2, p3: 3, opt: false b.valid_method_with_opt(2,3,4) # output: p1: 2, p2: 3, p3: 4, opt: true (Oh, and btw, the above example doesn't work for me)

    Read the article

  • Java: matching two different type of array

    - by sling
    Hi, I am doing a password login that requires me to match two array: User and Pass. If user key in "mark" and "pass", it should show successfully. However I have trouble with the String[] input = pass.getPassword(); and the matching of the two arrays. String[] User = {"mark", "susan", "bobo"}; String[] Pass = {"pass", "word", "password"}; String[] input = pass.getPassword(); if(Pass.length == input.length && user.getText().equals(User)) { lblstat.setForeground(Color.GREEN); lblstat.setText("Successful"); } else { lblstat.setForeground(Color.RED); lblstat.setText("Failed"); }

    Read the article

  • Mysql IN clause, php array

    - by robert knobulous
    I know that this has been asked and answered before, but for the life of me I cannot find where I am going wrong. My code is below. $backa = array("1", "7", "8", "9", "12"); $backaa = implode(",", $backa); /* code to create connection object $wkHook */ $getOpt=$wkHook->prepare("select movementId, movementName from Movement where movementId IN ($backaa) order by movementName asc"); $getOpt->execute(); $getOpt->store_result($id, $name); Every time I run this I get one of two errors depending upon how I use the $backaa variable. More often than not I get a call to a non-object error indicating that $getOpt is not a proper Mysql query. I have tried every fashion of quoting, bracketing, etc for the $backaa variable but it's just not working for me. What obvious thing am I missing?

    Read the article

  • perl array of hashes sorting

    - by srk
    use strict; my @arr; $arr[0][0]{5} = 16; $arr[0][1]{6} = 11; $arr[0][2]{7} = 25; $arr[0][3]{8} = 31; $arr[0][4]{9} = 16; $arr[0][5]{10} = 17; sort the array based on hash values so this should change to $arr[0][0]{6} = 11; $arr[0][1]{9} = 16; $arr[0][2]{5} = 16; $arr[0][3]{10} = 17; $arr[0][4]{7} = 25; $arr[0][5]{8} = 31; first sort on values in the hash.. when the values are same reverse sort based on keys... Please tell me how to do this.. Thank you

    Read the article

  • PHP 2D Array to MySQL Database

    - by Ashley Ward
    I have a PHP 2D array, many keys, each with one value, I need to put this into a MySQL database. The database has 8 fields. Eg. Field1, Field2, Field3, etc. I am trying to ensure value1 => field1, value2 =>field2, value3 => field3 and so on, when one record is full (i.e. after 8 values) a new record should be created for the next 8 values and so on. I am aware that the 1st, 9th, 17th, 26th values etc, will need an insert statement and the intermediate values will be an update statement. What is the best way of going about this?

    Read the article

  • Multi-dimensional array in php

    - by pundit
    Hi all, I would like to create a multi-dimensional array with two variables but don't know how. This is what i have so far; $_SESSION['name'][] = $row_subject['name']; $_SESSION['history'][]= $_SERVER['REQUEST_URI']; I wanted to know if this is possible? $_SESSION['name'][] = $row_subject['name'],$_SERVER['REQUEST_URI']; i want to get the name of a programme which is generated via a data base and also to retrieve the url. What i am actually doing once the name is retrieve, i want to make that a link which the url would be necessary. any help would be appreciated. Thanks

    Read the article

  • Finding indexes of each element in a multidimensional array in ruby

    - by Shreyas Satish
    Eg :a=[["hello", "world"], ["good", "lord"], ["hello", "lord"]] I need to find and record the indexes of each word with respect to the super-array. i.e hello => 0,2 world => 0 lord => 1,2. here's my shot ,but its very amateurish and lengthy. all_tokens=tokens.flatten all_tokens.each do|keyword| tokens.each do|token_array| if token_array.include?keyword x << i end i=i+1 end y[k] = x.clone y=y.clear end

    Read the article

  • Pascal error with array

    - by Donator
    program s;       type info = record                    name, surname: string;                    min, sec: integer;       end;       arrays = array[2..50] of info;       var A: arrays; begin       A[1].name := 'name'; end. What is wrong with that? It gives me range check error and I have no idea what is that.

    Read the article

  • C# assign char and char array to string?

    - by Bopha
    char character = 'c'; string str = null; str = character.ToString();//this is ok char[] arrayChar = { 'a', 'b', 'c', 'd' }; string str2 = null; str2 = string.Copy(arrayChar.ToString());//this is not ok str2 = arrayChar.ToString();//this is not ok. I'm trying to converting char array to string, but the last two attempts don't work. Other source I found and they have to create new string type, but I don't know why. Can someone give me little explaination, thanks.

    Read the article

  • Search object array for matching possible multiple values using different comparison operators

    - by Sparkles
    I have a function to search an array of objects for a matching value using the eq operator, like so: sub find { my ( $self, %params ) = @_; my @entries = @{ $self->{_entries} }; if ( $params{filename} ) { @entries = grep { $_->filename eq $params{filename} } @entries; } if ( $params{date} ) { @entries = grep { $_->date eq $params{date} } @entries; } if ( $params{title} ) { @entries = grep { $_->title eq $params{title} } @entries; } .... I wanted to also be able to pass in a qr quoted variable to use in the comparison instead but the only way I can think of separating the comparisons is using an if/else block, like so: if (lc ref($params{whatever}) eq 'regexp') { #use =~ } else { #use eq } Is there a shorter way of doing it? Because of reasons beyond my control I'm using Perl 5.8.8 so I can't use the smart match operator. TIA

    Read the article

  • remove duplicates from object array data java

    - by zahir hussain
    hi i want to know how to remove duplicates in object. for example cat c[] = new cat[10]; c[1].data = "ji"; c[2].data = "pi"; c[3].data = "ji"; c[4].data = "lp"; c[5].data = "ji"; c[6].data = "pi"; c[7].data = "jis"; c[8].data = "lp"; c[9].data = "js"; c[10].data = "psi"; i would like to remove the duplicates value from object array. thanks and advance

    Read the article

  • Numpy modify array in place?

    - by User
    I have the following code which is attempting to normalize the values of an m x n array (It will be used as input to a neural network, where m is the number of training examples and n is the number of features). However, when I inspect the array in the interpreter after the script runs, I see that the values are not normalized; that is, they still have the original values. I guess this is because the assignment to the array variable inside the function is only seen within the function. How can I do this normalization in place? Or do I have to return a new array from the normalize function? import numpy def normalize(array, imin = -1, imax = 1): """I = Imin + (Imax-Imin)*(D-Dmin)/(Dmax-Dmin)""" dmin = array.min() dmax = array.max() array = imin + (imax - imin)*(array - dmin)/(dmax - dmin) print array[0] def main(): array = numpy.loadtxt('test.csv', delimiter=',', skiprows=1) for column in array.T: normalize(column) return array if __name__ == "__main__": a = main()

    Read the article

  • array won't work actionscript 3

    - by steve
    I've tried everything. Arrays are quite simple so I don't know why this doesn't function: var menuList:Array = [menu_bag_mc,menu_chips_mc,menu_coke_mc,menu_cup_mc,menu_deodorant_mc,menu_fork_mc,menu_knife_mc,menu_lighter_mc,menu_milk_mc,menu_pill_mc,menu_rings_mc,menu_shampoo_mc,menu_spoon_mc,menu_straw_mc,menu_toothbrush_mc,menu_trashbag_mc,menu_water_mc]; function captureAllClicks(event:MouseEvent):void { trace(menuList.indexOf(event.target)); } stage.addEventListener(MouseEvent.CLICK, captureAllClicks); Every time I click on any of the items on the stage (which are all given the instance names listed above. each is a tweening movieclip containing a button) I get a trace of -1. WHY?!

    Read the article

  • iterating through an array

    - by Farstucker
    Iterating though an array isn’t a problem but what if I only wanted to incremented only when the method is called? Im not even sure if this would work but is there an easier way of doing this int counter; string[] myArray = {"foo", "bar", "something", "else", "here"}; private string GetNext() { string myValue = string.Empty; if (counter < myArray.Length) { myValue = myArray [counter]; } else { counter = 0; } counter++; return myValue; }

    Read the article

  • change last key name from array in php

    - by robertdd
    i want to be able to change the last key from array i try with this function i made: function getlastimage($newkey){ $arr = $_SESSION['files']; $oldkey = array_pop(array_keys($arr)); $arr[$newkey] = $arr[$oldkey]; unset($arr[$oldkey]); $results = end($arr); //echo json_encode($results); print_r($arr); } if i call the function getlastimage('newkey') it change the key!but after if i print the $_SESSION the key is not changed? why this?

    Read the article

  • declaring a 2D array of pointer objects

    - by Tyler Stennette
    I'm having a tough time figuring out how to instantiate a 2D array of pointer objects. Here is how I'm doing it: Pieces* chessBoard[9][9]; When I want to set it to an actual object pointer, I'm doing the following: chessBoard[1][1] = new Rook(p1Rook); Rook is a class that inherits attributes from the Pieces class and p1Rook is a char variable set to 'R'. This class also implements virtual functions (not pure virtual) from Pieces such as move() or getPiece() that are unique to the particular chess piece. However, when I compile my program, I get the following error: ChessBoard.cpp:69: error: expected type-specifier before ‘Rook’ ChessBoard.cpp:69: error: cannot convert ‘int*’ to ‘Pieces*’ in assignment Can someone please explain what I should change to get rid of this rather annoying persistent error? I would appreciate it.

    Read the article

  • Basic class returns onject reference instead of Array

    - by php-b-grader
    I have very basic class: class Customer { protected $id; protected $customer; public function __construct($customer_id) { $this->id = $customer_id; return $this->set_customer(); } protected function set_customer() { $query = mysql_query("SELECT * FROM customer WHERE id = '$this->id'"); $this->customer = mysql_fetch_row($query); return $this->customer; } } $customer = new Customer($order->customer->id); print_r($customer); This is not doing what I want it to but I understand why... $customer returns a reference to the Customer Object... But what I want is the MySQL row array from the mysql_fetch_row() call... What am I missing?

    Read the article

  • pass php array to jquery with getJSON

    - by robertdd
    i want to pass a php aray to jQuery: $.getimagesarr = function() { $.getJSON('operations.php', {'operation':'getimglist'}, function(data){ var arr = new Array(); arr = data; return arr; }); } var data = $.getimagesarr(); if (data){ jQuery.each(data, function(i, val) { .... }); } it return undefined in php i have this: function getimglist(){ $results = $_SESSION['files']; echo json_encode($results); } it is possible?

    Read the article

  • routine to generate a 2d array from two 1d arrays and a function

    - by intuited
    I'm guessing that there's a word for this concept, and that it's available in at least some popular languages, but my perfunctory search was fruitless. A pseudocode example of what I'd like to do: function foo(a, b) { return a * b // EG } a = [ 1, 2, 3 ] b = [ 4, 5, 6 ] matrix = the_function_for_which_I_search(foo, [a, b] ) print matrix => [ [ 4, 8, 12], [5, 10, 15], [6, 12, 18] ] // or function concatenate(a,b) return a.b } print the_function_for_which_I_search( concatenate, [ a, b ]) => [ [ '14', '24', '34'], ['15', '25', '35'], [16', '26', '36'] ] In other words, function_for_which_I_search will apply the function given as its first argument to each combination of the elements of the two arrays passed as its second argument, and return the results as a two-dimensional array. I would like to know if such a routine has a common name, and if it's available in a python module, cpan package, ruby gem, pear package, etc. I'm also wondering if this is a core function in other languages, maybe haskell or R?

    Read the article

< Previous Page | 32 33 34 35 36 37 38 39 40 41 42 43  | Next Page >