w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Get Integer from textbox in windowbuilder
You will have to parse it from the String: try { int actualValue = Integer.parseInt(text.getText()); System.out.println(actualValue); } catch (NumberFormatException e) { System.out.println("Not a number"); } Be aware that this might throw a NumberFormatException if the text cannot be cast to an integer.

Categories : Java

Convert letter from textBox to an integer
Your first task is to capture only the first character from the input: string str = textBox1.Text; char chr = str[0]; // get first character Now the character can be directly converted to an integer, for example: int number = (int)chr; However, the character 'A' is actually represented by the number 65, 'B' 66, and so on (see ASCII), so you'll have to subtract that from your input to get the intended value: int value = number - 65; Or if you prefer: int value = number - (int)'A'; Now you might want to normalize input so a character 'a' will be treated as 'A', so in the end it would look a bit like this: string str = textBox1.Text.ToUpperCase(); char chr = str[0]; int number = (int)chr; int value = number - 65; MessageBox.Show(value.ToString());

Categories : C#

warning: return makes pointer from integer without a cast but returns integer as desired
A void * is a pointer to anything, you need to return an address. void * myfunction() { int * x = malloc(sizeof(int)); *x=5; return x; } That being said you shouldn't need to return a void * for an int, you should return int * or even better just int

Categories : C

Need number returned to be an integer instead of float, error: integer expression expected
Are the decimal places not useful for other things? I wouldn't destroy data just because you don't need it at the moment; you should transform it when you take it out of the database: select trunc(prnct_change) from count_statistics The default behavior of TRUNC() on a number is to remove all decimal places.

Categories : Oracle

Is it possible to convert an integer pointer to the actual integer located at that memory location?
Yes, you can do it using references, like this: int &a(*aPtr); At this point, any changes done to the int stored at aPtr will be reflected in a: *aPtr = 123; cout << a << endl; // 123 is printed *aPtr = 456; cout << a << endl; // 456 is printed Of course in order for this to work you need to ensure that the constant 0x457FB indeed represents a valid address available for reading and writing by your program.

Categories : C++

Algorithm to find smallest integer by swapping a pair of digits in given integer
First count each digit, store it in an array (counts[10]). Going from the left, check the digits (following is the description of the loop): Check that there's a digit in counts which is smaller than it. Pick the smallest one. Exception: 0 is not allowed for the very first digit. If there's one, swap, you're done (exit the loop!). Otherwise decrement the digit in counts, and go for the next digit. For each digit you do O(1) work. So the whole algo is O(n). For swapping you want to use the least significant digits (furthers to the right). You can either store these locations on the initial lookup, or just before swapping you can search for the first matching digit starting from the end.

Categories : Algorithm

Crystal Reports 2011 - Integer to String and back to Integer
You cannot have a single formula that outputs multiple data types. Instead, you can have your formula output a string like you already mentioned: if isnull({Command.DAYS_OUT}) then "Missing" else totext({Command.DAYS_OUT}) Then, to get your font color formatting the way you want, you can use the original integer value: if isnull({Command.DAYS_OUT}) or {Command.DAYS_OUT} < 0 then crRed else if {Command.DAYS_OUT} in 1 to 30 then crYellow else crBlack And then do the same for the font type: if isnull({Command.DAYS_OUT}) then crRegular else if {Command.DAYS_OUT} < 0 or {Command.DAYS_OUT} in 1 to 30 then crBold else crRegular

Categories : String

Java: Splitting Integer into 2 Bytes and then combining them again into an Integer
Java uses signed bytes (C, C++, C# operate with unsigned ones), so you should take care of complement representations (for negative values): int in = 500; byte[] data = new byte[2]; // <- assuming "in" value in 0..65535 range and we can use 2 bytes only data[0] = (byte)(in & 0xFF); data[1] = (byte)((in >> 8) & 0xFF); int high = data[1] >= 0 ? data[1] : 256 + data[1]; int low = data[0] >= 0 ? data[0] : 256 + data[0]; int res = low | (high << 8);

Categories : Java

Comparing the filenames with an integer and reading the filename that is less than the integer
Try using expr ... filename="123" ToCompare=100 cmp=`expr $filename - $ToCompare` if [ $cmp -lt 0 ] ; then #file has lower value else #file has higher value fi

Categories : Bash

Find a random integer which creates another integer, when using percentages
I would just select a percentage and work backwards from the answer to arrive at the question: p * x = answer | 0 < p < 100, p = 5k, 100 <= x < 10000 So, pick your percentage: p = (5 * rand(1, 9)) / 100.0; Make sure your 100 <= answer / p < 10000: answer = rand(100, p * 9999); Solve for the 'unknown': x = p / y

Categories : Java

Print all unique integer partitions given an integer as input
I would approach it this way: First, generalize the problem. You can define a function printPartitions(int target, int maxValue, string suffix) with the specification: Print all integer partitions of target, followed by suffix, such that each value in the partition is at most maxValue Note that there is always at least 1 solution (provided both target and maxValue are positive), which is all 1s. You can use this method recursively. So lets first think about the base case: printPartitions(0, maxValue, suffix) should simply print suffix. If target is not 0, you have to options: either use maxValue or not (if maxValue > target there is only one option: don't use it). If you don't use it, you should lower maxValue by 1. That is: if (maxValue <= target) printParti

Categories : Algorithm

how to insert int value from a textbox to field in database that is in integer type?
CREATE TABLE transaction ( transactionid int IDENTITY(1,1) PRIMARY KEY,transactionname varchar(MAX) NOT NULL). It will autoincrement your id column. WebConfig <connectionStrings> <add name="connstring" connectionString="Data Source="";User ID="";Password= "";Initial Catalog=""" providerName="System.Data.SqlClient"/> </connectionStrings> c# SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["connstring"].ToString()); SqlCommand cmd = new SqlCommand(); con.open(); cmd.commandtext="insert into transaction (transactionname) values ('"+TextBox1.Text+"')"; cmd.ExecuteNonQuery(); con.Close();

Categories : Asp Net

How to take integer from user in android,manipulate and place in another textbox
take edittext values using EditText e1 = (EditText) findViewById(R.id.edittext1); String myEditValue = e1.getText().toString(); int value = Integer.parseInt(myEditValue); //similarly for second text view now do your desired mathematical operation value 3=value2*value1 similarly to set values EditText e3 = (EditText) findViewById(R.id.edittext3); e3.setText(Value3.toString());

Categories : Java

Using SparseIntArray instead of HashMap with putSeriazable
1) How important is using SparseIntArray() instead of the HashMap ? It depends on how you are using it. But unless you are trying to represent many and/or large "arrays" like this, the difference is unlikely to be significant. Note that Java SE doesn't have any sparse array classes, and it is not normally an issue. 2) Should I go through the trouble of making SparseIntArray serializable? (My first idea is making a wrapper class that implements Serializable, is this the right way to go?) See above, and below. (Yes, that sounds reasonable ... if you need to go to this bother.) The SparseIntArray class (source code) uses a pair of int arrays to represent the keys and values in the mapping, and uses binary search to do the lookup. The keys are kept in order with no "holes" an

Categories : Java

Extending TreeMap to only take Integer -> Integer mappings?
You don't need to extend or cast anything. Use generics: Map<Integer, Integer> foo = new TreeMap<Integer, Integer>(); ...and you're done.

Categories : Java

How to decide whether the result of an integer expression is an integer
You can use % to compute the remainder. int denom = 2 * n; int numer = 30 - n * (n - 1); if (denom) { if (numer % denom == 0) { then good to go } } else { /*...denominator is 0! */ }

Categories : C++

Convert integer to integer array or binary
First of all, an array starts from the index of 0 instead of 1, so change the following line of code: Log.d("TAG", " Data " + array[1] "," + array[2] + "," + array[3]); To: Log.d("TAG", " Data " + array[0] "," + array[1] + "," + array[2]); Next, the following line of code: array[i] = string.getChar(i); You are trying to get a character value to an Integer array, you may want to try the following instead and parse the value into an Integer (also, the "getChar" function does not exist): array[i] = Integer.parseInt(String.valueOf(string.charAt(i))); I hope I've helped. P.S - Thanks to Hyrum Hammon for pointing out about the String.valueOf.

Categories : Java

How could an integer variable store a reference to integer?
No, it is fine either way. The return value reference is not even necessary in this special case because you are not trying to modify the return value "on the fly" or the 'a' later, like when you use arithmetic operator overloads for that purpose, for instance

Categories : C++

Display picture only if textbox is blank
You can use IsNullOrEmpty if (String.IsNullOrEmpty(textBox1.Text)) { //Show Picture pictureBox1.ImageLocation = "locationofimg"; } else { //Hide Picture pictureBox1.ImageLocation = ""; } To get fancy with it. On form_Load() set the picturebox to nothing private void Form1_Load(object sender, EventArgs e) { pictureBox1.ImageLocation = ""; } Then in the Textbox Change Method private void textBox1_TextChanged(object sender, EventArgs e) { if (String.IsNullOrEmpty(textBox1.Text)) { pictureBox1.ImageLocation = ""; } else { pictureBox1.ImageLocation = "ImageLocation.com.etc"; } } This will make the box empty to start with no image and as you type it will pop up. If the boxes text is deleted fully the image will vanish.

Categories : C#

obtain the integer from a model after s.get_model()
Possible example using Z3py x= Int('x') s = Solver() s.add(x + 3 == 5) print s.check() m = s.model() print m y = (m.evaluate(x)) z = y + 4 print simplify(z) Output: sat [x = 2] 6

Categories : C++

Yii Passing an integer value to model->find('type',2)
It should have to be $proflist = CHtml::listData(Person::model()->find('type =2'),'id','firstname'); or $proflist = CHtml::listData(Person::model()->findAllByAttributes(array('type' => '2')),'id','firstname'); Read more about method find() You should learn more from Yii official document http://www.yiiframework.com/doc/api/1.1/CActiveRecord

Categories : SQL

Check integer is bit rotation of another integer
I would use Integer.rotateLeft or rotateRight func static boolean isRotation(int a, int b) { for(int i = 0; i < 32; i++) { if (Integer.rotateLeft(a, i) == b) { return true; } } return false; }

Categories : Java

Can integer with space still read as integer?
int guess = Integer.parseInt(stringGuess.trim()); see http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#trim%28%29

Categories : Java

How do I make an integer go up and display on a JLabel?
Make sure that Integer win is not null. I do see one reason behind NPE is that win is null and you are saying win++ on a null object. During doing ++, while autoboxing, it will throw NPE. also Make sure JLabel is not null. If you are calling a method on a null object, it will throw NPE. Either Integer win or JLabel Win is null or both are null. Else I don't see any reason behind NPE.

Categories : Java

Integer.parseInt Error : java.lang.Integer.parseInt(Unknown Source)
I think this is your problem: while (bufferedReader.readLine() != null) { result += Integer.parseInt(bufferedReader.readLine()); } You're calling readLine() twice there. You should store the initial result in a variable, and the reuse that result in the parseInt() call.

Categories : Java

How can I display different integer values for the Edit and create view
One possibility is to add an additional property to your model for the view only and ensure that is in megabytes for the view in the controller and then convert back as part of the save. That way your display is always in megabytes and the database is in bytes. (Or have I missed something?)

Categories : Asp Net Mvc

Generate progressive (dense, not like AutoField that skip some) integer in a django model
It seems, as reported also here, that is a DBMS related thing that has to do with concurrence and perfomance avoiding gapless sequence. So I've solved that issue using an aux model 'Progressive' which holds, locks and increments a row. # models.py from django.db import models, transaction class Counter(models.Model): name = models.CharField(max_length=40, unique=True, db_index=True) n = models.PositiveIntegerField(default=1) class Customer(models.Model): def save(self, *args, **kwargs): super(Customer, self).save(*args, **kwargs) if self.cod == '': with transaction.commit_on_success(): try: counter = Counter.objects.select_for_update().get(name='Customer') except Counter.DoesNotExist:

Categories : Django

Why is unsigned integer overflow defined behavior but signed integer overflow isn't?
The historical reason is that it is only the representations for signed values that may differ according to the implementation: one's complement, two's complement, sign-magnitude. For an unsigned type there is no reason for the standard to allow variation because there is only one obvious binary representation (the standard only allows binary representation). Relevant quotes: C99 6.2.6.1:3: Values stored in unsigned bit-fields and objects of type unsigned char shall be represented using a pure binary notation. C99 6.2.6.2:2: If the sign bit is one, the value shall be modified in one of the following ways: — the corresponding value with sign bit 0 is negated (sign and magnitude); — the sign bit has the value −(2N ) (two’s complement); — the sign bit has

Categories : C++

Function checking if an integer type can fit a value of possibly different (integer) type
I propose a solution using numeric_limits #include <limits> using std::numeric_limits; template <typename T, typename U> bool CanTypeFitValue(const U value) { if (numeric_limits<T>::is_signed == numeric_limits<U>::is_signed) { if (numeric_limits<T>::digits >= numeric_limits<U>::digits) return true; else return (static_cast<U>(numeric_limits<T>::min() ) <= value && static_cast<U>(numeric_limits<T>::max() ) >= value); } else { if (numeric_limits<T>::is_signed) { if (numeric_limits<T>::digits > numeric_limits<U>::digits) //Not >= in this case! return true;

Categories : C++

Converting 16-bit integer to 8-bit integer?
You can use the bitwise operators of the language: you need to shift the number 8 and 0 bits to the right to get the first and second digits, respectively (and you should also mask them with 255 so that exactly one byte is extracted): int16_t i = 0x1234; uint16_t n = i; // because shifting the sign bit invokes UB int8_t hi = ((i >> 8) & 0xff); int8_t lo = ((i >> 0) & 0xff);

Categories : Misc

what is difference between integer a = 5 and new Integer(5)?
for primitive data types like int the equality operator will check if the variables are equal in value for reference data types like your java.lang.Integer objects, the equality operator will check if the variables reference the same object. In the first case, you have two "new" and separate integer objects, so the references are different

Categories : Java

Integer+Integer in java 1.4
Java 1.4 did not have autoboxing of Integer variables. That came along in Java 1.5. See What's New in Java 1.5: Autoboxing/Unboxing Prior to that you had to do things like: Integer i1 = new Integer(10); Integer i2 = new Integer(20); Integer i3 = new Integer(i1.intValue() + i2.intValue());

Categories : Java

Which design pattern and SOLID principle to be applied if i have to display differnt message on for each item inside a Dynamic integer collection
School assignment? I don't see why there's a need for design patterns for the given requirements, since it can be realized with just a few lines of code. Design patterns can be powerful, but should only be used when necessary. static void Main(string[] args) { foreach(var item in Generate(1, 1000)) { Console.WriteLine("{0}: {1}", item.Key, item.Value); } } private static IEnumerable<KeyValuePair<int, string>> Generate(int init, int max) { int current = init; var stringBuilder = new StringBuilder(); while (current <= max) { if (current % 3 == 0) stringBuilder.Append("FUZZ"); if (current % 5 == 0) stringBuilder.Append("BIZZ"); if (current % 7 == 0) st

Categories : C#

Why is absolute of Integer.MIN_VALUE equivalent to Integer.MIN_VALUE
Read this in Effective Java by Joshua Bloch. I found the answer for this question and here is the explanation: Computers work with binary arithmentic, the logic of Math.abs in java or the absolute function in any language is like below: if(num >= 0) return num; else return (2's compliment of the num); Note : How to find 2's compliment For a given number, we find it's 1's compliment first and then add 1 to it. For e.g. Consider our number to be 10101 1's compliment = 01010 2's compliment = 01011 (added 1 to the 1`s compliment) Now, for the sake of making it easy and clear, let us say that our Integer(signed) size is 3 bit, then here is the possible list of numbers which can be produced using the four bits: 000 --> 0 (0) 001 --> 1 (1) 010 --> 2 (2) 011 --> 3 (

Categories : Java

expected type: java.lang.Integer, actual value: java.lang.Integer
By the looks of it you are missing the default constructor. Hibernate looks for the default constructor to create instances before playing around with import and export of mapping information between DB and class.

Categories : Java

If blank text is in textbox then blank action
This line of code will set the value of the input $("#textinput").val("evil"); You said you wanted to test the current text if ($("#textinput").val() === "evil") { alert("Watch your language!"); }

Categories : Jquery

How can I display the client ID of a model property into a view?
Unless I'm misunderstanding your question, there is an HtmlHelper that does exactly what you want: IdFor @Html.IdFor(x => x.Address.PostCode) // Will return Address_PostCode Although, that's for MVC4 and up. For MVC3, you will need to roll your own. See this SO.

Categories : C#

Helper method accessing Display(Name) from given model property
You could retrieve it from the metadata of the property. Example: public static IHtmlString MyHelperFor<TModel, TValue>( this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression ) { var metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData); string name = metadata.DisplayName; return new HtmlString(string.Format("<th>{0}</th>", html.Encode(name))); } and then: @model MyViewModel ... @Html.MyHelperFor(x => x.SomeProperty) Assuming that SomeProperty on your view model is decorated with the [Display] or [DisplayName] attributes: [DisplayName("foo bar")] public string SomeProperty { get; set; } or: [Display(Name = "foo bar")] public string SomeProperty { get; set; } the custom helper wi

Categories : C#

Why is it not possible to call List not with List even if Integer extends Number?
Because you could e.g. add an instance of a different subclass of Number to List<Number>, e.g., an object of type Double, but obviously you shouldn't be allowed to add them to List<Integer>: public void myMethod(List<Number> list) { list.add(new Double(5.5)); } If you were allowed to call myMethod with an instance of List<Integer> this would result in a type clash when add is called.

Categories : Java

C++ insert 2-dimensional array of integer into another 2-dimensional array of integer
Arrays in C++ are FIXED SIZE -- so there's no way 'push down' data into an array, changing its size. You can only copy stuff, overwriting (part of) the destination array, but leaving it the same size. If you want to do this, you need to either use something (like std::vector) that allows for a changing size, or create a NEW array of the desired size and copy the data into it: int C[6][2]; std::copy(A, A+2, C); std::copy(B, B+2, C+2); std::copy(A+2, A+4, C+4);

Categories : C++



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.