package floatandint;
import java.util.Scanner;
public class FloatAndInt {
public static void main(String[] args){
float f = 0f;
Scanner sc = new Scanner(System.in);
System.out.println("请输入浮点型数字:");
try{
f = sc.nextFloat();
System.out.println("整数部分:" + (int)f);
System.out.println("小数部分:" + getXiaoshu(f));
}catch(Exception e){
e.printStackTrace();
}
}
private static String getXiaoshu(float f) {
return (f + "") .substring(1+ ((f + "").indexOf("."))) ;
}
}
float f = 1.1212f;
String sf = String.valueOf(f);
System.out.println(sf.substring(0, sf.indexOf('.')));
System.out.println(sf.substring(sf.indexOf('.')+1, sf.length()));