JOptionPane

编程入门 行业动态 更新时间:2024-10-11 07:36:04
本文介绍了JOptionPane - 输入对话框程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

编写一个程序,使用输入对话框读取三个测试标记,每个测试标记100个。程序丢弃最低标记,并在消息对话框中显示两个较高标记的平均值。

Write a program that uses input dialog boxes to read three test marks, each out of 100. The program discards your lowest mark and shows the average of the two higher marks in a message dialog box.

这是我有多远,我不知道从这里做什么,任何帮助将不胜感激:

This is how far i got and i dont know where to do from here, any help would be appreciated:

import javax.swing.JOptionPane; public class Average { public static void main (String [] args){ String test1, test2, test3, avg; test1= JOptionPane.showInputDialog("Please input mark for test 1: "); test2= JOptionPane.showInputDialog("Please input mark for test 2: "); test3= JOptionPane.showInputDialog("Please input mark for test 3: "); } }

推荐答案

import java.util.SortedSet; import java.util.TreeSet; import javax.swing.JOptionPane; import javax.swing.JFrame; public class Average { public static void main(String [] args) { String test1= JOptionPane.showInputDialog("Please input mark for test 1: "); String test2= JOptionPane.showInputDialog("Please input mark for test 2: "); String test3= JOptionPane.showInputDialog("Please input mark for test 3: "); int int1 = Integer.parseInt(test1); int int2 = Integer.parseInt(test2); int int3 = Integer.parseInt(test3); SortedSet<Integer> set = new TreeSet<>(); set.add(int1); set.add(int2); set.add(int3); Integer [] intArray = set.toArray(new Integer[3]); JFrame frame = new JFrame(); JOptionPane.showInternalMessageDialog(frame.getContentPane(), String.format("Result %f", (intArray[1] + intArray[2]) / 2.0)); } }

更多推荐

JOptionPane

本文发布于:2023-11-28 03:52:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1640845.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:JOptionPane

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!