|
| ||||||||||
| Tags: java, number system, programming language, utilities, whole number |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Determine a whole number in java
I really began in java and make a little program I would like to know how little test if the square root of a number is an integer or not. I would have the equivalent function is_int () in php Code: int i;
if (whole?(Math.sqrt(i)))
{
...
} but such i.length does not. How to determine whole numbers in java. Thanks in advance. |
|
#2
| |||
| |||
| Re: Determine a whole number in java
Hello, Try the following example Code: float f = Math.sqrt(i);
if (Math.rint(f)== f) {
....
} Code: i =5588126;
System.out.System.out.println((""+ i).length()); |
|
#3
| |||
| |||
| Re: using the math() function in java
Hello, You can try the following code and you will get the whole numbers using java. Just have a look at it Code: try{
int x =(int) Math.sqrt(i);
}catch (ClassCastException e){
System.out.System.out.println("This is not an integer");
} |
|
#4
| |||
| |||
| Re: Determine a whole number in java
Hello, You can also try this example, it will give the same result but it is well formatted and well defined. If you like it then you can go with this code Here is the code: Code: double in = 26;
double y = Math.sqrt(in);
int x = (int)y;
if ( y% x! = 0 ) out.System.out.println("This is not an integer"); |
|
#5
| |||
| |||
| Re: code for whole numbers
Hello, The following code is more simpler that the others, try it and see how the output is given by the program Code: if (Math.rint(nb)== nb) {
System.out.System.out.println("Integer");
/ / processing
}
else{
System.out.System.out.println("No integer");
} |
|
#6
| |||
| |||
| Re: Determine a whole number in java
Hello, This example gives you the same output using the different logic and even some of the different methods from java are used. Have a look at the code Code: int a = 123857;
char[] b = Integer.function toString() {
[native code]
}(has).toCharArray();
char c[] = { b[b.length-1]};
String s = String.copyValueOf(c);
System.out.System.out.println(s); |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Determine a whole number in java" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to determine the model number of my Toshiba satellite pro T455 laptop? | Naotau | Portable Devices | 4 | 27-07-2011 08:13 AM |
| How can we determine which application meets Java or DotNET eligibility criteria | NathanDS | Software Development | 5 | 16-10-2010 02:45 PM |
| How to format a number in java? | kamina23 | Software Development | 4 | 20-01-2010 08:01 PM |
| Determine maximum number of recent documents in Windows Server 2008 | Computer_Freak | Tips & Tweaks | 1 | 28-07-2009 05:52 PM |
| Determine number of columns in a file | Chrisch | Software Development | 3 | 12-05-2009 11:19 PM |