package com.test;
public class IntFrmStringCheck {
private static String str=null;
public int compare(int str )
{
int res=0;
//res ==1 => Positive number
//res==0 => non-integer
try
{
//float s=Float.parseFloat(str);
int s=Integer.parseInt(str);
//Allow only positive numbers
if(str.contains("-"))
{
res=0;
}
else if(s==0)
{
res=0;
}
else
{
res=1;
}
}
catch(NumberFormatException e)
{
res=0;
System.out.println("INSIDE CATCH:"+ e);
}
finally
{
//
}
// return res;
}
public static void main(String[] args)
{
System.out.println("RESULT:"+compare("45"));
}
}
}
No comments:
Post a Comment