//浮点数.substring(0,浮点数.lastIndexOf("."))
String num;
Scanner input = new Scanner(System.in);
System.out.print("输入一个浮点数:");
num=input.next();
System.out.print(num.substring(0,num.lastIndexOf(".")));
代码如下:
import java.util.Scanner;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个数:");
double num = sc.nextDouble();
int sum = (int)num;
System.out.println(sum);
}
}