I've a question on rounding doubles on 0.05 As far as i know there is no class method that is able to do this. To achieve this rounding i have the following code:
The first problem is that the numbers don't round in IntelliJ.
Example: ('s in Dutch) Geef de vorige kilometerstand: 125 Geef de huidige kilometerstand: 900 Geef het aantal getankte liters: 50 Verbruik voor 775km: 6.451612903225806/100km
That 6.4516..... is the problem, how can I make it 6.45/100km?
I am trying to cast an integer into a double. it works but I need two decimal number after the dot and for example I can print 7.51 but how can I get it to print 7.50 and not 7.5
public int compareTo(Money o){ int d1 = (this.dollars * 100) + this.cents; int d2 = (o.dollars * 100) + o.cents; return d1 - d2; }
On my main method I have
public static void main(String[] args){ Money money1 = new Money(10, 49); Money money2 = new Money(2, 99); System.out.println("result: " + "$" + (double)money1.compareTo(money2)/100); }
It prints 7.5 but I want it to print 7.50, how do I do this .....
So i need to write a program that prompts the user for 3 double numbers x, y, z that outputs 2x^3 + 3y^5 + 3x^3y^2 +xyz with
(1) 4 digits precision (2) with a ',' to separate thousands (3) all digits of the result including the precision are put to 20 positions (from right to left)
I am not really sure what it is suppose to look like or how to start it.how to mix Math.pow with multivariable and printf.
So I have to convert strings to double numbers and there can be no exception.
The strings that aren't numbers or do not fit into a set criteria have to be discarded.
When I try to write this I get an exception when a non-numeric is entered and the code stops.
What can I do? Also, am I finding the average of the array correctly?
import java.util.*; public class Grades{ public static void main(String args[]){ int arraycount = 0; final int SIZE = 10; int validArraycount = 0; final int ValidArraySize = 10;
Write method distance to calculate the distance between two points (x1, y1) and (x2, y2). All numbers and return values should be of type double. Incorporate this method into an application that enables the user to enter the coordinates of the points.
Hints:
- The distance between two points can be calculated by taking the square root of
( x2 - x1 )2 + ( y2 - y1 )2
- Use Math class methods to compute the distance.
- Your output should appear as follows:
Type the end-of-file indicator to terminate
On UNIX/Linux/Mac OS X type <ctrl> d then press Enter
On Windows type <ctrl> z then press Enter
Or Enter X1: 1
Enter Y1: 1
Enter X2: 4
Enter Y2: 5
Distance is 5.000000
Type the end-of-file indicator to terminate
On UNIX/Linux/Mac OS X type <ctrl> d then press Enter
for (int i = 0; i < letters.length; i++) { double relativeFreq = (onesAverage()/letters[i]); char a = characters.charAt(i); double j = score[i]; System.out.printf();//ToDo
Above is my current code. Basically- There is a string called characters of length 26 (1 char for each letter in alphabet), a double relativeFrequency value which does a calculation and the end result is a number with lots of decimal numbers. The score array has set double values within the array.
What I want to do is create a print f statement where I print out each of the values I initialized above WITH specific amounts of spaces in between. So it should be in this order:
a (spaces) j (spaces) relativeFreq (newLine).
Between J and relativeFreq there should be 4 spaces, however if the value in relativeFreq is greater than 10 (it won't be greater than 100)- then there should be 3 spaces. Everytime I try to create a printf statement my code ends up crooked for some of the values.
for (int i = 0; i < letters.length; i++) { double relativeFreq = (onesAverage()/letters[i]); char a = characters.charAt(i); double j = score[i]; System.out.printf("%c %.4s %.4s%n",a, j, relativeFreq);
1. ask user to input a decimal 2. output 1 - confirms the input 3. output 2 rounds the input value to the nearest integer.
Here is what I have so far:
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.util.Scanner; public class IT145Exercise13 { static Scanner console = new Scanner(System.in);
[Code] .....
Results with input of 5.25: run: Enter a decimal: 5.25 You entered 5.25
The integer value is 5 YES however,
BUILD SUCCESSFUL (total time: 6 second)
However, if the input is 5.95 here are the run results:
run: Enter a decimal: 5.95 You entered 5.95 The integer value is 5 Here I expect 6 BUILD SUCCESSFUL (total time: 6 second
Not sure how to ask the output of the variable integerOut to be rounded to the nearest integer?
for standard deviation my output is not rounded to the 10's place, how can I make it round to the 10's place. Here is my code.
import java.util.*; public class chapter7 { public static final int Max_Number_Scores = 100; public static int fillArray(double[] scores) { System.out.print("You entered "); for (int i = 0; i < scores.length; i++) { System.out.print(scores[i] + " ");
Write a method named diceSum that prompts the user for a desired sum, then repeatedly rolls two six-sided dice until their sum is the desired sum. Here is the expected dialogue with the user:
Desired dice sum: 9 4 and 3 = 7 3 and 5 = 8 5 and 6 = 11 5 and 6 = 11 1 and 5 = 6 6 and 3 = 9
This is my code:
import java.util.Scanner; import java.util.Random; public class mod { public static void main(String[] args) { diceSum();
[Code] .....
it works for numbers 2 - 4, but any number from 5 - 12 just prints one output, which is not the correct desired sum.
I'm currently working on a loan calculator... The only problem I'm having is occasional values that have very long decimals... How do I round the decimals?
My output of my app its outputting the correct data just no the format ...
code :
DatabaseQuery.java : import java.io.*; import java.sql.*; import java.util.*; public class DatabaseQuery
[Code] ....
Current output:
Stock holdings by User
User ID User Name Stock - Description ------------------------------------------- admin01 Default Admin DELL Dell Computer Corp admin01 Default Admin MSFT Microsoft Computer Corp
[Code] ....
Desired Output :
Stock holdings by User
User ID User Name Stock - Description ------------------------------------------- admin01 Default Admin DELL Dell Computer Corp MSFT Microsoft Computer Corp ORCL Oracle Corp
This was my initial question: I am confused as to why this won't return the desired value. I keep running into an infinite loop or data is returned that I searched.
I still need to work on whether a user enters a search that doesn't exist......that is where I am stuck....
code has been updated......
int low = 0; int high = subArray.length; while (low < high) { System.out.println("You have entered the while loop"); int mid = (low + high) / 2;
We are in the process of developing a e-commerce application. It is a web site for a book shop. It is a site very similar to Amazon.com where you can order books online. Front end is in Java Technology. There is however a concern about where to put the business logic.
I am suggesting to put all business logic in the Oracle Database, as stored procedures (i.e. packages). However, one of my colleague says that when you call a Oracle stored procedure from Java, it takes 2 round trips, one to validate the procedure and then to validate the input / ouput parameters of the procedure.
In a website application like what we are trying to build, is it sound advice to put all business logic in the DB? Or should it be in the middle tier (app. server) programmed in Java? Or should you spread in between the middle tier and DB? If so how?
Currently, my program converts Long values to String. And when I test it out, it do print out the correct output. However, when the converted String value is passed over to be written in a text file, it seems that BufferedWriter isn't printing out the outcome that it's supposed to be.
saltVs = Long.toString(saltV); System.out.print(saltVs); //will print out 79723172
Now the problem is here...It only prints out the last digit of the String value (instead of 79723172).
Here is my FileWriter/BufferedWriter part.
Why is that when I run my program using command prompt, it prints out the output that I wanted, but however when it comes to writing to the file, it doesn't come out right.
-In your main, you should create a thermostat and thoroughly test it. Be sure to showcase time passing and the temperature reaching the desired setting. Also, showcase switching modes from heating to cooling.
My question is, once it reaches the desired temp, would the thermostat turn off, and then how do you show switching from heating and cooling.
This is what prints.
Thermostat is: true Thermostat is: false The desired temp: 70.0 The current temp: 69.0 Tue Feb 25 19:06:21 CST 2014 Tue Feb 25 20:06:21 CST 2014 Thermostat is: true Thermostat is: false The desired temp: 70.0 The current temp: 70.0
Here is my Class:
import java.util.Random; import java.util.Date; public class Thermostat { private double currentTemp; private double desiredTemp; private double heatingThreshold; private double coolingThreshold;
I am working on a personal project and want to create a text editor to write my code. I am wondering how could I read the last input from the user and if say it was an open curly brace {, then like netbean's my editor will supply the closing curly brace. My java experience is limited but I have tried to read key board input and a few other options that did not work.
I tried to create file and write the output of my program in it in java when i use WriteLong then the file does not contain long value, how I create this file my program is to print prime numbers between 500000 to 10000000
public class primenumber { public static void main(String[] args) { long start = 5000000; long end = 10000000; System.out.println("List of prime numbers between " + start + " and " + end); for (long i = start; i <= end; i++) { if (isPrime(i)) { System.out.println(i);
I've just written a program that generates 100 numbers that range from 0 ~ 25 using arrays, the program calls another method that sorts the even numbers into a separate array and returns the array. I need it to display both arrays, however, when I run my program, the numbers of both arrays are mixed together, and I'm not sure how to separate them.
[ public class Array1 { public static void main(String[] args) { int array [ ] = new int[100]; for (int i = 0; i < array.length; i++) { array[i] = (int) (Math.random() * 26);
I'm trying to make a program that generates 20 random integers between 1 and 20 and then prints the list of random numbers to the screen. After that, I want to print a different list to screen with the same numbers from the first list only skipping any number that has been already printed to the screen. So two lists are printed to the screen. The first one has 20 random numbers. The second one has those same 20 numbers but only prints the numbers in the first list that aren't duplicated. So if m
y list of 20 random integers contains three 2s and two 14s, only one 14 and one 2 is printed to the second list. Currently, my code generates 20 numbers from 1 to 20 and stores those numbers in an array but I don't know how to print solve the second part of my problem. I don't know how to print the s different list only without duplicate numbers. As a result, my output is nothing because it doesn't print any number from the first list as oppose to skipping only duplicate one.
public void randomNum(){ System.out.println("Twenty random integers: "); int max = 20; // max value for range int min = 1; // min value for range Random rand = new Random(); int[] all = new int[20];
I have to make a program that prompts the user to enter 10 numbers and at the end it prints out the distinct numbers and then the other numbers that weren't repeated...
I have the part where it prints out the distinct numbers but I stuck on how to make it print out the other numbers that didn't repeat...
import javax.swing.JOptionPane; public class DistinctNumbers { public static void main(String[] args) { String getInput; int input; int[] numbers = new int[10];