ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Code Snippets  >>  Programming Code  >>  Java Code  >>  J2EE Code
 
 


 

 
 J2SE Code interview questions  J2SE Code Interview Questions
 J2EE Code interview questions  J2EE Code Interview Questions
 J2ME Code interview questions  J2ME Code Interview Questions
Question
How to convert string containing decimal point into integer
in java? For example given a string like "3.14" as input how
to get integer 3 as result.
 Question Submitted By :: Pradeep
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How to convert string containing decimal point into integer in java? For example given a string like "3.14" as input how to get integer 3 as result.
Answer
# 1
/* How to convert string containing decimal point into integer
in java? For example given a string like "3.14" as input how
to get integer 3 as result. */

String myStr = "3.14";
Int myInt = Float.valueOf(myStr).intvalue();
 
Is This Answer Correct ?    19 Yes 2 No
Pradeep
 
  Re: How to convert string containing decimal point into integer in java? For example given a string like "3.14" as input how to get integer 3 as result.
Answer
# 2
class StringToInt {
	public static void main (String[] args) {
    String s="3.14";
    double i=Double.parseDouble(s);
    int i1=(int)i;
    System.out.println (i1);
 
    }
}
 
Is This Answer Correct ?    15 Yes 2 No
Indresh_ips
[Yen Exall Soft Pvt.ltd]
 
 
 
  Re: How to convert string containing decimal point into integer in java? For example given a string like "3.14" as input how to get integer 3 as result.
Answer
# 3
I don't know
 
Is This Answer Correct ?    6 Yes 4 No
Subramanyam
 
  Re: How to convert string containing decimal point into integer in java? For example given a string like "3.14" as input how to get integer 3 as result.
Answer
# 4
/***************************************************/

import java.io.*;

class StringToInt 
{
	public static void main(String a[]) throws 
IOException
	{
		String s;
		BufferedReader br = new BufferedReader(new 
InputStreamReader(System.in));
		do{
			s=br.readLine();
			System.out.println("U R Sting 
is: "+s);
		   }while(s.equals(" "));
		try
		{
		  double d = new Double(s);
		  int j = (int)d;
		  System.out.println(j);
		}catch(NumberFormatException e)
		{
			System.out.println(" Your String is 
Not a Number:..  ");
		}
	}
}
 
Is This Answer Correct ?    3 Yes 2 No
Shiva Kumar
 
  Re: How to convert string containing decimal point into integer in java? For example given a string like "3.14" as input how to get integer 3 as result.
Answer
# 5
For the above given question 3 is answer while converting
decimal to integer
 
Is This Answer Correct ?    0 Yes 0 No
Rajasekaran.p
 
  Re: How to convert string containing decimal point into integer in java? For example given a string like "3.14" as input how to get integer 3 as result.
Answer
# 6
String str = "5.22";
Int result = Float.valueOf(mystr).intValue();
// value of result is 5
 
Is This Answer Correct ?    1 Yes 1 No
Troya
 

 
 
 
Other J2EE Code Interview Questions
 
  Question Asked @ Answers
 
How to read MS-word document in java without displaying junk (unnecessary) data? Cognizent1
How to convert string containing decimal point into integer in java? For example given a string like "3.14" as input how to get integer 3 as result.  6
Can you forward data from a servlet to a regular .java class that is not a servlet?  2
how to display date after one month using from today date in jsp TCS3
 
For more J2EE Code Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com