How To Round The Numbers

Sep 27, 2014

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?

View Replies


ADVERTISEMENT

Round Up Double Numbers To Desired Value?

Mar 28, 2015

I have a double/big decimal value with 2 decimal places....What I want is that if decimal value is .01 - .49, it should round up to 0.50.

Then if decimal value is between 0.51 - 0.98, it will round up to 0.99.

Is there a function in double that can do this? How can I do this?

View Replies View Related

How To Round The Result To Nearest Integer

Jan 11, 2015

My program is attempting to:

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?

View Replies View Related

Standard Deviation - Round To 10s Place

Dec 2, 2014

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] + " ");

[code]....

View Replies View Related

Loan Calculator - How To Round Decimals

May 20, 2014

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?

View Replies View Related

Efficient Method To Round Double On 0.05

May 27, 2015

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:

Example:
164.67 -> 164.70
173.33 -> 173.35
0.02 -> 0.05 

double calculatedQuantity = 0.0;

  // Formula to calculate the average working hours in a month
  int totalWeeksInYear = 52;
  int totalMonthsInYear = 12;

[Code].....

View Replies View Related

JavaFX 2.0 :: Round Corner In TableView Header

May 20, 2014

I'm doing a bit of styling in TableView. The result is quite nice but I can't make the left top corner round. This is the actual result:
 
[URL] ....
 
And this is the css :

.table-view {
    -fx-background-color: transparent;   
}
/*HEADER */
.table-view .column-header{      

[Code] .....

I would also like the top left corner was round.

View Replies View Related

Will SP Call From Java Make 2 Round-trips To DB?

Feb 5, 2014

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?

View Replies View Related

Round Decimal Number Into 2 Decimal

Apr 2, 2014

Here is my code and i want to convert number into 2 decimal but this code not give me result how to check my code.

import javax.swing.JOptionPane;
public class showtime{
public static void main(String[] args){
double total_mili=System.currentTimeMillis();
JOptionPane.showMessageDialog(null,total_mili, "Total milisecond",JOptionPane.INFORMATION_MESSAGE);
double seconds=total_mili/60;
double sec=(double)(seconds * 100) / 100.000;
JOptionPane.showMessageDialog(null,seconds, "Total Second",JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null,sec, "Total Second",JOptionPane.ERROR_MESSAGE);
}
}

View Replies View Related

Long Type Output File - Print Prime Numbers Between Given Range Of Numbers

Aug 22, 2014

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);

[Code] ....

View Replies View Related

Generate 100 Numbers Using Arrays - Sort Even Numbers Into Separate Array And Display Both

Apr 24, 2014

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);

[Code] .....

View Replies View Related

Print 2 Lists - 20 Random Numbers And Another List Without Duplicate Numbers

Feb 1, 2015

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];

[Code] ....

View Replies View Related

User To Enter 10 Numbers And At The End Prints Out Distinct And Non-repeated Numbers

Nov 23, 2014

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];

[Code] ....

View Replies View Related

Generate Two Arrays - One With All Positive Numbers And Another With Negative Numbers

Mar 10, 2015

Create an integer array with 10 numbers, initialize the array to make sure there are both positive and negative integers. Write a program to generate two arrays out of the original array, one array with all positive numbers and another one with all negative numbers. Print out the number of elements and the detailed elements in each array.

public class problem3 {
public static void main(String[]args){
int[] numbers = {1, 2, 3, 4, 5, -1, -2, -3, -4, -5};
for (int i = 0; i<numbers.length;){
if(i>0){
System.out.println(numbers);
}
else
System.out.println(numbers);
}
}
}

View Replies View Related

Generate Random Numbers Without Certain Numbers In Range

Jul 31, 2014

I tried out doing number (generated randomly) != (another number) but that does not work. If I for example want a number between 1 and 10, but I do not want the number 5, what can I do in order to make this happen?

View Replies View Related

List All Prime Numbers Between Two Entered Numbers

Oct 17, 2014

Program is to list all prime numbers between two entered numbers.

import java.util.Scanner;
public class question6 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter lower int:");
int x = input.nextInt();

[Code] .....

View Replies View Related

Sum Of First N Numbers

Jul 1, 2014

I wrote a program to find the sum of first 10 numbers using the for loop... here is the piece of code

public class Sum {
public static void main(String[] args) {
int sum = 0;
for (int N=0; N<= 10; N++) {
sum = sum + N;
}
System.out.print("The sum of first 20 numbers is " + sum);
}
}

I tried to write the same program using the while loop but with no success. How can i write this using while loop?

View Replies View Related

ID Numbers Are All 0

Jun 4, 2014

I don't know what I did to screw this up, but I had this code working to increment each employee ID by one every time a new employee was added. I tried to move the whole employeeID and newEmployeeID elements out of the constructor because everyone keeps telling me how bad it is to have those in the constructor. However, now, every time I add an employee, their ID number turns out to be 0. I have two other aspects of this project that are due soon, and if I can't fix this part, I won't be able to move forward to the other parts (which I am also stuck on at this point). The codes that are being used are as follows:

import java.io.*;
import java.util.*;
import java.nio.file.*;
import java.text.NumberFormat;
public class Employee
{
// instance variables
private String firstName;
private String lastName;
private int employeeID;
static int newEmployeeID = 0;

[Code] ....

View Replies View Related

How To Add Two Numbers Using RMI

Apr 3, 2014

how to add two numbers using RMI..This very simple example is taken from Chapter 24 of "Java 2: The Complete Reference" by P.Naughton and H.Schildt.The example is overly simplified but it still illustrates the basic steps in creating an RMI distributed program.

This example provides step-by-step directions for building a client/server application by using RMI. The server receives a request from a client, processes it, and returns a result. In this example, the request specifies two numbers, the server adds these together and returns the sum.(Of course, this program is intended only to illustrate the basic RMI mechanism.)The next subsections provide main steps in writing an RMI program

Define an interface that declares remote methods.The first file AddServerIntf.java defines the remote interface: it includes one method that accepts two double arguemnts and returns their sum. All remote interfaces must extend the interface Remote, that defines no methods: its purpose is simply to indicate that an interface uses remote methods.All remote methods should throw a RemoteException

import java.rmi.*;
public interface AddServerIntf extends Remote {
double add(double d1, double d2) throws RemoteException;
}
Implement the remote interface and the server

The second source file AddServerImpl.java implements the remote interface:

import java.rmi.*;
import java.rmi.server.*;
public class AddServerImpl extends UnicastRemoteObject
implements AddServerIntf {
public AddServerImpl() throws RemoteException {
}
public double add(double d1, double d2) throws RemoteException {
return d1 + d2;
}
}

All remote objects must extend UnicastRemoteObject which provide the functionaly that is needed to make objects available from remote machines. The third source file AddServer.java contains the main program for the server machine. Its primary function is to update the RMI registry on that machine. This is done by using the rebind() method of the Naming class (it is in java.rmi API). That method associates a name with an object reference.

import java.net.*;
import java.rmi.*;
public class AddServer {
public static void main(String args[]) {
try {
AddServerImpl addServerImpl = new AddServerImpl();

[code]....

Develop a client (an application or an applet) that uses the remote interface..The fourth source file AddClient.java implements the client side of this distributed application. This program requires 3 command line arguments: the IP address or name of the remote server, and two numbers that are to be summed.

The application forms an URL string using the rmi protocol, the first command line argument and the name "AddServer" that is used by naming registry of the server. The the program calls the method lookup() of the Naming class to find a reference to a remote object. All remote method invocations can then be directed to this object.The client program illustrates the remote call by using the method add(d1,d2) that will be invoked on the remote server machine from the local client machine where the client runs.

import java.rmi.*;
public class AddClient {
public static void main(String args[]) {
try {
String addServerURL = "rmi://" + args[0] + "/AddServer";
AddServerIntf addServerIntf =

[code]...

If you do not have an Internet connection, you can run all programs of this example on your local machine (both server and client). In this case, you can run

java AddClient 127.0.0.1 567 999

to use the "loop back" address (127.0.0.1) for the local machine. This will allow you to test the entire RMI mechanism without actually having to install the server on a remote computer.

View Replies View Related

How To Sum Up Two Numbers Of Fractions

Apr 3, 2014

how to sum up two numbers of fractions?

View Replies View Related

Different Way To Add Cubed Numbers 1-10?

Feb 12, 2014

/*
* Put your documentation header here.
*/
import java.util.Scanner;
 public class Lab5{
  /**
* Returns an integer whose value is a^3 (a cubed).
* @param any integer to be cubed
* @return a^3 (a cubed)

[code]...

The last part with int a-j...... Is there a better way of doing this, like possibly putting into a loop and showing output from maybe a single piece of information?

View Replies View Related

Sum Of Numbers Between Two Integers

Nov 19, 2014

I was trying to get sum of numbers between two given integer and managed to do it.

public int sum(int a, int b) {
int sum=0;
while(a <= b) {
sum+=a;
a++;
}
return sum;
}

in here; when I enter the values i.e 2 and 5, it calculates 2+3+4+5 and gives me the result 14.

my question is, how could I exclude a and b in this calculation ( in this case exclude 2 and 5 and return 3+4 )

Bonus question ; how could I only calculate the odd (or even) numbers between those integers?

View Replies View Related

Numbers In Certain Range?

Sep 7, 2014

program that calculates and prints the sum of all numbers between two limits as the user types. Like if the user types 1 and 10 on the upper limit, it prints the following text: "1+2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55".

View Replies View Related

Odd And Even Numbers With Boolean?

Apr 14, 2014

how to determine if an integer is even or odd by using a boolean method. I think I have the method right, but it's calling the method into the main that has got me stumped.

import java.util.Scanner; 
public class Odd_Even {
public static void main(String[] args) {
//Scanner, variables
Scanner input = new Scanner(System.in);
int number;
 
[code]....

View Replies View Related

GUI Show ODD Numbers

Dec 3, 2014

I want to make app in netbeans. When i write numbers in JTextField like 1,2,3,4,5,6... it should show me in JOptionPane information window result of ODD numbers.

View Replies View Related

How To Add Two Numbers In Same Row Of A File

Sep 26, 2014

I need to add two integers in the same row of a file, separated by tab

my file abc.txt has the following entry

12 123
15 456

My program needs to add 12 with 123 and 15 with 456

I am being able to split the two entries in a row and convert them to integer but i dont know how to treat them as separate numbers and add them. For example if i try to add then 12 adds with 12 and 123 adds with 123. wheres it should be 12+123

Here is my program

import java.io.*;
public class test {
public static void main(String[] args) {
String s = "";
FileInputStream finp = null;

[Code] .....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved