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
ADVERTISEMENT
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
Apr 21, 2015
I am currently trying to solve a programming problem on this site, and the problem includes working on a 100 digits of decimal places of a certain irrational number. I tried using BigDecimal class but it displays, correctly me if I am wrong, just 20+ decimal digits. Is there other way to do this?
View Replies
View Related
Apr 25, 2014
why exactly this isn't printing out the correct way.I'm supposed to print out 100 elements from an array but assign them random integers between 0 and 9.I've tried troubleshooting the issue and when I do it seems i'm only getting one element assigned.
public class Exercise_6_7{
public static void main(String[] args){
int[] counts = new int[100];
for(int i=0; i<counts.length; i++){
counts[i] = (int)(Math.random()*10);
[code]....
View Replies
View Related
Apr 26, 2014
designing a program which allows you to buy stuff from the jframe with 10x items each with different pricing, so once you click the image button the cost of that is displayed in the textfield, ive been trying to set the jtextfield to a decimal point but have not been able to so far,
if (source == jBSofa) {
System.out.println("Sofa");
{
dTotal = dTotal + 599.99;
jTotal.setText(Double.toString(dTotal));
DecimalFormat myFormatter = new DecimalFormat("#####.#");
String output = myFormatter.format(dTotal);
a visual aspect of it.
View Replies
View Related
Apr 18, 2015
Right now it displays a number like this "$25.0" and I want it to display it like this "$25.00" and don't know how to do it.
View Replies
View Related
Jan 23, 2014
If I have 0123.45 string and trying to get 12345 as result. I am trying regex like below.
String s="0123.45";
s = s.replaceAll("^0*([0-9]+).*", "$1");
It gave result 123 as leading zeros removed that is one of the things that I want. How do I achieve 12345?
View Replies
View Related
Jan 27, 2015
Consider this small program and output.
public class Floating{
public static void main( String[] args ){
System.out.println( 2.80 - 1.75 );
}
}
The output is 1.0499999999999998. Why not 1.05?
View Replies
View Related
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
May 19, 2014
//read the file
//make the numbers 1 string line
//count the number of repetitiveness in the string for the numbers
//display four lowest ones
import java.io.*;
import java.util.*;
public class Lottery2
[Code] ....
when I run it the array gets sorted but how do i keep the data in other words
what it is supposed to do is grab numbers from a file, and give me the lowest 4 numbers back. I know the numbers using the array but how do i pull out the lowest 4 and keep the data true no matter what numbers or how many of them are in the file.
View Replies
View Related
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
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
Mar 21, 2014
For example, if i am given 9864
Imust output 4689
Without use of arrays.
View Replies
View Related
Jan 7, 2015
the output of this:
int x = (int) 24.6;
View Replies
View Related
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
View Related
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
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
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
Sep 21, 2014
Develop the class “Account” to be used by a bank. The Account class should have a single instance variable “balance”. Remember that balance must be a floating point number. The required methods for the Account class are shown below.
The Account class “debit” method should return a Boolean and should not allow an overdraft. If a withdraw greater than the current balance is attempted, the function should immediately return “false” and do nothing else.
Develop a test class to thoroughly test all aspects of the Account class. DO NOT change the class name or instance variable name given or the required method names as detailed below.
Account
1 constructor with no parameters (default balance to 0)
1 constructor with a balance parameter
setBalance method
getBalance method
credit method
debit method
I have the test class done, I won't need to put that in till later. My main problem is I'm not sure how I'm going to be able to get debit and setBalance to work together with each other.
public class Account
{
protected double balance;
// Constructor to initialize balance
public Account( double amount ) {
balance = amount;
[Code] ....
You can see I'm stressed out by not reading over my code. I already have the "Debit" in use, just have to change it. Which I did.
View Replies
View Related
Jul 16, 2014
Java programming, I decided to write a code today that would convert decimal numbers to hexadecimal numbers. Unfortunately, it does not compile. The error message is "cannot find symbol - variable A", and might be the same error for the other variables B,C,D,E,F.
Here is my code:
public class dec2hex
{
public static void main (String [] args)
{int nbr = 99;
char a = A;
char b = B;
char c = C;
[Code] ....
View Replies
View Related
Feb 28, 2014
This problem is from Java . It asks me to convert a binary number in to decimal. How to program this in java? I am not able to find an effective algorithm to convert in to Java.
View Replies
View Related
Mar 24, 2014
So I have 2 args[] one that reads the file name in the same directory and the other that tries to count how many of any letter (maybe even words) in the txt file ....
View Replies
View Related
Jan 29, 2015
We have been given an assignment to create a small library, with the following classes Library, Book, Author and Copy. With a given class Biblio which has predefined code and adds the books to the class book in an arraylist in Class Copy.
The UML Domain is attached so you know the flow of the classes Everything is working fine and the generated output is correct.
There is just one method in class Library that is not working, the int method has to count the number of Copy's based on the Class Book (String):
I have to go through the Arraylist in Class Copy and look for a specific book and return the number of copy's.
I have tried multiple steps using a for loop Now I have found a similar post the uses hashset, I have tried below code but the return comes back with 0. (There are 3 copy's)
package domein;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import domein.Boek;
import domein.Exemplaar;
[code]....
View Replies
View Related
Mar 28, 2014
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class Paragraph {
public static void main(String[] args) throws FileNotFoundException, IOException
[Code] .....
View Replies
View Related
Jul 20, 2010
i want to create a program in java which counts the number of prints taken from a printer..
View Replies
View Related
Feb 4, 2015
I am using count++ in my program in order to count the number of division that occurs. It works but outputs:
The number of divisions is 1
The number of divisions is 2
The number of divisions is 3
The number of divisions is 4
The number of divisions is 5
All i want is the last line. How do I solve this?
import java.util.Scanner;
public class Program3
{
public static void main(String [] args)
{
int div;
[Code] ....
View Replies
View Related