//作者:janushu //日期:2017/9/20 //功能判断两个数的大小 import java.io.*; public class CompareToNumDemo{ public static void main(String[] args){ try{ //输入流 从键盘上输入一个数 InputStreamReader isr = new InputStreamReader(System.in); //缓存读取一个数 BufferedReader br = new BufferedReader(isr); System.out.println("请输入第一个数"); //从控制台读取一行数据 String snum1 = br.readLine(); System.out.println("请输入第二个数"); String snum2 = br.readLine(); float fnum1 = Float.parseFloat(snum1); float fnum2 = Float.parseFloat(snum2); if(fnum1 > fnum2){System.out.println(fnum1+"大于"+fnum2);} if(fnum1 == fnum2){System.out.println(fnum1+"等于"+fnum2);} if(fnum1 > fnum2){System.out.println(fnum1+"小于"+fnum2);} }catch(Exception e){ System.out.println("无法判断"); } } }
时间: 2024-12-26 00:24:42