Formatting Double To Fixed Number Of Fractional Digits

Apr 6, 2014

Where do I find a subroutine similar to this:

String formatDouble(double dblNum,int NumOfDecDigits) { }

For years I have been using output subroutines I wrote long ago.

Now I need this kind and can't remember where it is.

How do I print doubles to a fixed number of digits to right of the point?

View Replies


ADVERTISEMENT

Double Number Formatting

Oct 29, 2014

I have a real number. example:

double number = 1.95842175;

I want to split it into 2 integers:

int a1 = 1;
and
it a2 = 95 (2 numbers after '.')

How?

View Replies View Related

User To Input Integer And Then Outputs Both Individual Digits Of Number And Sum Of Digits

Feb 2, 2015

Goal is to: Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits.

First I don't know where I made mistakes here, and the only error it finds right now is that str2 was not initialized and I cannot figure out where/when to initialize it.

import javax.swing.JOptionPane;
public class DigitsAndSum {
public static void main (String[] args) {
String str1;
String str2;
int int1 = 0;
int int2 = 0;

[Code] ....

View Replies View Related

Occurrence Of Digits In A Number

Aug 29, 2014

Make a program which takes input from the user (6-digit number) and check how many times each digit gets repeated in the number. Java GUI was used (Netbeans 6.5.1).This is my code. I took the input via a JTextField named tf and displayed the output on JTextArea ta.

- arrays not used as we haven't studied them yet

int num= Integer.parseInt(tf.getText());
int no=num;
if(num<100000)
ta.setText("Invalid Input. Please Enter 6 digit number");
int n1= num%10;
num=num/10; //stores last digit

[code]....

How do I omit the last 5 lines? This problem occurs whenever I input a digit with any recurring digit.What changes/additions should I make?

View Replies View Related

Calculate SUM And AVERAGE Of ODD Number Digits Between 25 And 75

Jun 19, 2014

You are to write a parallel program that will receive a large array of unsorted integers containing digits from 0 to 99. The program will have to calculate the SUM and AVERAGE of ODD number digits between 25 and 75 (inclusive).

The user may specify the size or the array and the total processor that the machine has. The size of the array must be divisible by number of processor. Based on the given size, the computer will generate random integer numbers automatically to populate the array.

The program should display the status of the calculation for each processor. The result should be displayed after all calculations are completed.Error messages should be displayed appropriately

a) Write a sequential (non-parallel) program that will accomplish above task.
b) Write a concurrent (parallel) program that will produce the result of the above task.

View Replies View Related

Formatting Number As Money In Java

Apr 23, 2014

Is this masking in currency 1,000,000,000 inserting special characters in number of formatting the numbers ....

View Replies View Related

Count Number Of Digits After Decimal Point?

Jul 21, 2014

Given a Numbers instance, whose fields are arrays of all the built-in Java numeric types (int, long, float, double, big-decimal, etc), write a method to sort all the numbers into a master list, and then print out the numbers where the number of digits past the decimal point is equal to the index of the number in the master list.

Is there a function in Java that will give me just the numbers after the decimal? I tried Decimalformat but couldn't get it to work. Here is what I have so far; however, I think I might be on the wrong track.

public class Numbers
{
public static void main(String[] args) {
Byte bNum = new Byte((byte) -50);
Integer iNum = new Integer(168);
Long lNum = new Long(100000L);
Short sNum = new Short((short) 10000);
Float fNum = new Float(12.19f);
Double dNum = new Double(23.123);
BigDecimal bd = new BigDecimal("3.14159265358979323846");

[code]....

View Replies View Related

Putting Digits Within A Number In Ascending Order

Mar 21, 2014

For example, if i am given 9864

Imust output 4689

Without use of arrays.

View Replies View Related

Parallel Program - Calculate SUM And AVERAGE Of Odd Number Digits Between 25 And 75

Jun 11, 2014

You are to write a parallel program that will receive a large array of unsorted integers containing digits from 0 to 99. The program will have to calculate the SUM and AVERAGE of ODD number digits between 25 and 75 (inclusive). The user may specify the size or the array and the total processor that the machine has. The size of the array must be divisible by number of processor. Based on the given size, the computer will generate random integer numbers automatically to populate the array.

The program should display the status of the calculation for each processor. The result should be displayed after all calculations are completed.Error messages should be displayed appropriately

a) Write a sequential (non-parallel) program that will accomplish above task.
b) Write a concurrent (parallel) program that will produce the result of the above task.

View Replies View Related

Take User Input And Display Sum Of Digits Of Entered Number

Nov 6, 2014

I have returned with yet another problem but I think this one might be a bit easier to fix.

So the whole MO of this program is to take user input, and display the sum of the digits of the number they entered. I am supposed to do this by utilizing methods. So far this is what I have and when I compile it tells me that it "cannot find symbol", which I don't understand as I define what "m" is in the for loop. The other error is that it says:

"Exercise6_2.java:22: error: incompatible types: possible lossy conversion from long to int
return result;
^

I don't understand why it's giving me this error nor do I understand why result seems to inherently be an int. (Also the public static int sumDigits(long n) method was given to me by the book so that is what I am supposed to use).

import java.util.Scanner;
public class Exercise6_2 {
public static void main(String[] args) { 
Scanner input = new Scanner(System.in);
System.out.println("Enter a integer");
long n = input.nextLong();

[Code]...

View Replies View Related

Prompt User To Input Integer And Then Output Both Digits Of Number And Their Sum

Jun 7, 2015

Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits. 
 
Now I have a code for spacing out the integers, and I have a separate code for adding the digits. But I am not sure how to merge them together. Both of them work independently
 
Spacing code:
import java.util.*;
public class SumoftheIntegers
{
static Scanner console=new Scanner(System.in);
public static void main(String []args) {
int num1, test, rem;
int counter = 0;

[Code]...

Now the sum of the integers code:
 
import java.util.Scanner;
public class sum
{
    public static void main(String[] args)
    {
        // Create a Scanner
        Scanner input = new Scanner(System.in);
// Enter amount
        System.out.print("Enter an integer: ");
        int integer = input.nextInt();

[Code]...

View Replies View Related

Generating Double Number From The Range

Apr 18, 2014

I am trying to generate a double number from the range [-1,2]

so what i did is this

xs[i]= Math.random() *(2-(-1))+(-1);

I did that as a loop to generate multiple numbers and i got this result:

initial x values 2.17 2.66 3.04 2.81 1.83 2.66 3.67 2.81 1.04 3.1 3 1.23 1.44 3.5 3.84 3.03 1.7 2.79 4 1.43

see some numbers are out of range! and i don't know why aren't there any minus numbers...

View Replies View Related

Double RelativeFrequency Value Which Does Calculation / End Result Is Number With Lots Of Decimal Numbers

Nov 24, 2014

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

View Replies View Related

User Input Data As String And If Verified As Valid Number Then Convert Into Double

Nov 11, 2014

I am writing a code in which a user inputs data as a string and that data must be verified as a valid number. A valid number is anything from 0-100. Then all valid numbers are converted into double numbers.

I am having trouble in how to write the validation part of the code.

Is it suppose to be an if, else statement? And if so how is it suppose to be validated?

View Replies View Related

Swing/AWT/SWT :: JTable With Fixed Row

Nov 9, 2008

My JTable has a row, row number 0, which I always want to be at the top.I tried the following two approaches, both without success:

1- Use a custom table cell renderer for the header, and create a header of two rows. the second row is my JTextField.

Problem: I cannot get the JTextField to function properly. (I've seen examples with a checkbox in the header, but that one just reacts to a click somewhere on the header, my textfield must be editable).

2- Use the first row of the table. This works quite nice. However, I must prevent row 0 to be re-ordered when sorting the table.

I was thinking to add a prefix (either something like "___" or "zzz" depending on current sorting mode), but I do not know which methods to adjust for this exaclty.

Another approach would be to have N textfields above the JTable in some layout (or two JTable's on top of each other).

However, Then I would need to react to the re-ordering and re-sizing of all columns as well, which does not seem easy to me.

View Replies View Related

Swing/AWT/SWT :: Layout With Fixed Heights And Gaps?

Jan 29, 2015

I'm trying to build a GUI that must look lik on the image above. There must be three JPanles, the one above, with buttons and combo boxes, must have fixed height and all three must have fixed vertical gaps between them. I'm trying laout after layout but somehow it's not working. I'm allowed to use only standard Swing layouts.

View Replies View Related

JSP :: Populate A Dropdown With Fixed / Static List Of Values?

Nov 3, 2014

I have a fixed list of 20+ values to be populated in a dropdown. The set of values are always going to remain the same, no future scope of modifications, additions or deletions.

Listing each of them as <option> in JSP is making the page look cluttered. Or is it better reading it as a comma-separated string from a properties file and then iterating to populate the dropdown.

What will be the best approach to populate such a dropdown in JSP?

View Replies View Related

Evaluation Of Expression - Operator Precedence Fixed Or Variable?

Feb 5, 2015

I just wanted to ask that while evaluating any expression,is the operator precedence fixed or it varies according to the compiler ,?

View Replies View Related

Program That Calculate Minimum Fixed Monthly Payment

Jun 11, 2014

I want to Write a program that calculates the minimum fixed monthly payment needed in order pay off a credit card balance.

the Amount is 3,500 the annual rate is 9.9%, the minimum payment is 2% a month. the fixed payment is 150.

By a fixed monthly payment, we mean a single number which does not change each month, but instead is a constant amount that will be paid each month.

The program should print out :

payment information:
new balance total .......
current payment due .......

if you make minimum payment (2%) you will pay of in .... months and you Will end up paying an estimated total of $........

if you make the fixed rate payment, you will pay of in .... months and you Will end up paying an estimated total of $........ and you will save $........

View Replies View Related

JavaFX 2.0 :: Make TextArea Background Gradient Fixed

Sep 27, 2014

I have a TextArea and want to set a linear-gradient as background, which works fine:
 
.text-area {
    -fx-background-color: linear-gradient(to bottom, red 0%, blue 100%);
}
 
The problem is that if the TextArea contains much text (and long scrollbars) it is nearly only red. Only if you scroll down to the bottom, it becomes blue.
 
I want the red-blue gradient always look the same, no matter how much text there is.
 
In HTML there's something like background-attachment: fixed, which would do the trick, but not so in JavaFX.
 
Can I achieve it nonetheless. Preferably without any ugly workarounds, like a transparent TextArea within another Pane where the wrapping Pane has the gradient.

View Replies View Related

Payroll System For Hourly / Fixed Monthly And Commission Paid Workers Of Company

Dec 21, 2014

I am doing a program where i have to implement a payroll system into a company for hourly, fixed monthly and commission paid workers. I also have to put the method which i did. the problem is I cant tell if my calculation is wrong or if i am missing a codes some where. The output is not giving me the answer that I was at least expected,

Here is my method:

{
< double total_deduction;>
< total_deduction = gross_pay - deduction;>
< return total_deduction;>
}
< public static double calGrossH(double hours_worked, double pay_rate)>

[Code] .....

I have done a lot researching and have come up with some search with almost the same calculation and I have also asked employees of a company on how they calculated hourly rate, commissions rate and fixed rate for all workers and gotten the same response but for some reason the output is not what it is supposed to output. here is my output.

<
un:>
<please enter the number of employees to be processed 31>
<please enter employee id number 3669>
<please enter employee first name>

[Code] ....

I dont know if I am missing some calculation somewhere or codes been researching and bussing my brains to figure out where is the missing codes or calculation.

View Replies View Related

Program For Airline Ticket Booking - Fixed Origin City And Five Destination Cities

Oct 26, 2014

I am doing a pretty basic program with a fixed origin city and five destination cities. I am having trouble with entering passenger details. This is what I tried, but then I cannot retain all passenger details to print later on in the final ticket.

System.out.println("Enter flight details of child passengers (below 12 years)");
System.out.println("Enter Name");
for(a = 1; a <= cp; ++a)
{
//cp is number of child passengers, a is loop variable
String name = br.readLine();
System.out.println("1. " + name);
}

View Replies View Related

How To Sum Digits

Jan 30, 2015

I have to seperate a number 9876 to 6 7 8 9, to 9 8 7 6. I need to know how to sum the digits. I have gotten to this point ::

import java.util.*;
public class week4program
{
static Scanner console = new Scanner (System.in);
public static void main(String[] args) {
int num1;
int digit;
int sum = 0;

[code]....

To this point its gives me the seperate integers. OK but how do I get the variable integers into seperate containers and then add them up?My assignment is to do that, and what I have above gets me to where I have seperate digits, but how do I catch them into seperate entities to be added to a sum?

View Replies View Related

Sum Of Odd Digits Of Input

Oct 14, 2014

I have it so it gives me the sum of any digit, i just cant figure out how to get only the odd digits to add up. for example if I were to type 123. The odd numbers = 4 but using this program i get 6

class SumOfDigits {
public static void main(String args[]) {
int sum = 0;
System.out.println("Enter multi digit number:");

[Code] ....

View Replies View Related

Sum Of Digits In Java

Feb 3, 2014

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

As you can see I'm using a while loop. For part B which is to modify to determine what integers of two, three, and four digits are equal to the sum of the cubes of their digits. So for example, 371 = 3³+7³+1³. How to do it? I need to wrap a for loop around my while loop...

View Replies View Related

Digit Sum Of Integer Is Sum Of All Digits

Oct 13, 2014

Digit sum of an integer is the sum of all its digits. For example, the digit sum of 123 is 1+2+3 = 6

and the digit sum of 99 is 9 + 9 = 18.

But how to write the programm that will count those numbers?

View Replies View Related







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