求一个java application程序,接受用户输入的一个浮点数,把它的整数部分和小数部分分别输出。
1个回答
展开全部
import java.util.Scanner;
/**
*
* @author top
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner scanner = new Scanner(System.in);
float inputNum=scanner.nextFloat();
System.out.println(inputNum);
String str_inputNum=String.valueOf(inputNum);
int count_inputNum=str_inputNum.length();
// System.out.println(count_inputNum);
int intNum=(int)inputNum;
System.out.println(intNum);
String str_intNum=String.valueOf(intNum);
int count_intNum=str_intNum.length();
// System.out.println(count_intNum);
float floatNum=inputNum-(float)intNum;
int count_floatNum=count_inputNum-count_intNum-1;
System.out.printf("%."+count_floatNum+"f",floatNum);
}
}
/**
*
* @author top
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner scanner = new Scanner(System.in);
float inputNum=scanner.nextFloat();
System.out.println(inputNum);
String str_inputNum=String.valueOf(inputNum);
int count_inputNum=str_inputNum.length();
// System.out.println(count_inputNum);
int intNum=(int)inputNum;
System.out.println(intNum);
String str_intNum=String.valueOf(intNum);
int count_intNum=str_intNum.length();
// System.out.println(count_intNum);
float floatNum=inputNum-(float)intNum;
int count_floatNum=count_inputNum-count_intNum-1;
System.out.printf("%."+count_floatNum+"f",floatNum);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询