double

Java - Most efficient way to convert string to double

这一生的挚爱 提交于 2019-12-13 18:17:33
问题 Hi I am reading from a text file and saving each line (split by a comma) into an array. The only problem is that most of the elements in the array are double values where as two elements are strings. As a result of this I had to make the array a String[] array. Due to this, whenever I want to perform some equations on the double values in the array, I have to first parse them as a double value. I am literally running 1000+ iterations of these equations, therefore my code is constantly parsing

Looks like double type variables have no methods. Something wrong with Java or NetBeans?

拥有回忆 提交于 2019-12-13 17:39:36
问题 According to Oracle I should be able to apply methods like .intValue() and .compareTo() to doubles but when I write dbl.toString() in NetBeans, for example, the IDE tells me that doubles can't be dereferenced. I can't even cast them to Integers in the form (Integer) dbl ! I have JDK 1.6 and NetBeans 6.9.1. What's the problem here? 回答1: The problem is your understanding of objects vs. primitives. More than anything else, you just need to recognize that the capitalized names are object classes

How do I receive input from a textbox in a JFrame?

天涯浪子 提交于 2019-12-13 17:26:59
问题 The following method extends a JFrame, but I need a swing textbox inside it to receive double values and store them in a variable. the textbox must be added to the container. public class myClass extends JFrame{ Container container; container = getContentPane(); //Item label JLabel labelText = new JLabel(); ... labelText.setText ("Item:"); container.add( labelText ); //Item name: Textbox //code to make a textbox, add it to the container, and store the value in a variable goes here 回答1: Use a

Specify a specific double precision literal in c#

拜拜、爱过 提交于 2019-12-13 16:06:55
问题 How can I specify a specific double precision literal or value in c#? For example, I would like to use the constant of the largest double value less than one in a program. The largest double less than one is 1.11111111 11111111 11111111 11111111 11111111 11111111 1111 x 2^(-1) in binary. Expressing this as a big-endian double in hex would be 0x3fe f ffff ffff ffff I can generate it with the following code: var largestDoubleLessThanOneBytes = new byte[] {0x3f, 0xef, 0xff, 0xff, 0xff, 0xff,

min change greedy algorithm in java

送分小仙女□ 提交于 2019-12-13 15:07:06
问题 Ok so i need to make a program to ask me for an amount of money, then I need it to tell me the least amount of coins to make it. The coins I can use are: dollars, quarters, dimes, nickels, and pennies. For example, When I run the program it's supposed to look like this: > run Coins Enter the amount of given money: [1.73] Give the seller 8 coins: 1 dollars, 2 quarters, 2 dime, 0 nickels, 3 pennies. This is What I have so far: import java.util.Scanner; class Coins { public static void main

How can I create a Single Click Event and Double Click Event when the Menu Button is pressed?

柔情痞子 提交于 2019-12-13 11:51:52
问题 I want to be able to detect a single click or a double click when the menu button is pressed. If a single click is detected one even will happen, if a double click is detected a different event will happen. Here is what I've tried(Using toast in place of events): private static final long DOUBLE_PRESS_INTERVAL = 250; // in millis private long lastPressTime; @Override public boolean onPrepareOptionsMenu(Menu menu) { // Get current time in nano seconds. long pressTime = System.currentTimeMillis

How are doubles represented when written to text files?

拟墨画扇 提交于 2019-12-13 10:09:58
问题 When you write a number of doubles to a file, in which format are they stored? Is it in byte format or string format? E.g. given 0.00083231. Is it stored with 10 bytes, where each byte represents one digit? Or is it stored as only 8 bytes, since the size of a double is 8 bytes? Assume that the language used is C++. 回答1: If you choose to write text, e.g. with formatted output like file << x , you get text. If you choose to write bytes, e.g. with unformatted output like file.write(&x, sizeof x)

JAVA: BMI Calculator using

血红的双手。 提交于 2019-12-13 10:01:42
问题 I am very new to java trying to build a simple BMI calculator using a constructor, a public instance method and a toString method. public class BMI { public BMI(String name, double height, double weight){ } public String getBMI() { return (weight/height); } public String toString() { return name + "is" + height + "tall and is " + weight + "and has a BMI of" + getBMI() ; } public static void main(String[] args) { } i don't really know what i'm doing, so all help is appreciated. If you know how

How to calculate a percentage

北慕城南 提交于 2019-12-13 09:53:48
问题 I want to calculate a percentage. My code is: Bot.Log("[ KEYBOT ] The total is " + (suctrades * totaltrades ) / 100 + "% !"); If I do this, I only get 0. What am I doing wrong? 回答1: Probably suctrades * totaltrades is still an int . The easiest way will be probably changing your code to: ((double)suctrades) * totaltrades/100 Or suctrades * totaltrades/100.0 To force using double instead of int 回答2: Try : Bot.Log("[ KEYBOT ] The total is " + ((double)suctrades * totaltrades ) / 100 + "% !"); I

Variable of type double not working when read by scanf()

眉间皱痕 提交于 2019-12-13 09:48:53
问题 #include <stdio.h> int main(){ double d; scanf("%f", &d); printf("%f\n\n", d); system("pause"); return 0; } This is what I get: error. This code is meant to read the variable double and display it on the screen but it does only display "0.0...". If I just change the variable type to float it does exactly what I want but if I make it a double it just reads '0'. Why? 回答1: In your code, scanf("%f", &d); is wrong. For scanf() , %f expects a pointer to float as argument. Quoting C11 , chapter §7