Java的数据输入

/*数据输入
导包:
    import java.util.Scanner;
创建对象:
    Scanner sc=new Scanner(System.in);
接收数据:
    int x= sc.nextInt();
*/ 

/*数据输入
导包:
    import java.util.Scanner;
创建对象:
    Scanner sc=new Scanner(System.in);
接收数据:
    int x= sc.nextInt();
*/

import java.util.Scanner;
public class Sannerdemo {
    public static void main(String[] args) {
//创建对象     
 Scanner sc=new Scanner(System.in);
//接收数据
int x= sc.nextInt();
//输出数据
System.out.println("x"+x);

题目:一座寺庙里面有三个和尚,他们的身高经过测量得出,请用程序实现获得三个和尚最高身高

import java.util.Scanner;
public class demo {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入第一个和尚的身高:");
        int height1= sc.nextInt();
        System.out.println("请输入第二个和尚的上身高");
        int height2= sc.nextInt();
        System.out.println("请输入第三个和尚的身高");
        int height3= sc.nextInt();
        int tempHeight=height1>height2?height1:height2;//三元运算符
        int maxHeight=tempHeight>height3?tempHeight:height3;//三元运算符
        System.out.println("这三个和尚最高的是:"+maxHeight+"cm");
    }
}

这里的height1>height2?height1:height2;

tempHeight>height3?tempHeight:height3三元运算符可换成'Math.max'调用

import java.util.Scanner;
public class demo {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入第一个和尚的身高:");
        int height1= sc.nextInt();
        System.out.println("请输入第二个和尚的上身高");
        int height2= sc.nextInt();
        System.out.println("请输入第三个和尚的身高");
        int height3= sc.nextInt();
        int  temptHeight= Math.max(height1, height2);
        int maxHeight= Math.max(temptHeight, height3);
        System.out.println("这三个和尚最高的是:"+maxHeight+"cm");
    }
}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现Java数据导入进度条的方式可以有多种,其中一种比较简单的方式是使用Swing组件JProgressBar。以下是一个基本的示例代码: ```java import javax.swing.*; import java.awt.*; public class DataImporter extends JFrame { private JProgressBar progressBar; public DataImporter() { super("Data Importer"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); progressBar = new JProgressBar(0, 100); progressBar.setValue(0); progressBar.setStringPainted(true); getContentPane().setLayout(new BorderLayout()); getContentPane().add(progressBar, BorderLayout.CENTER); setSize(300, 100); setLocationRelativeTo(null); setVisible(true); importData(); } private void importData() { // 在这里实现数据导入的逻辑 // 在每次处理数据时更新进度条的值 for (int i = 0; i <= 100; i++) { progressBar.setValue(i); try { Thread.sleep(50); // 暂停50毫秒模拟数据导入的过程 } catch (InterruptedException e) { e.printStackTrace(); } } JOptionPane.showMessageDialog(this, "数据导入完成"); } public static void main(String[] args) { new DataImporter(); } } ``` 在上面的代码中,我们首先创建了一个JFrame窗口,并在其中添加了一个JProgressBar组件。然后在importData()方法中实现了数据导入的逻辑,并在每次处理数据时更新进度条的值。最后通过JOptionPane弹出对话框提示用户导入操作已完成。 需要注意的是,由于数据导入可能会涉及到耗时操作,我们在这里将数据导入的过程放在了单独的线程中运行,这样可以避免阻塞UI线程。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值