什么是java程序流程图?我是刚开始学java的,不知道是什么意思,希望各位能帮我解释一下。

什么是java程序流程图?我是刚开始学java的,不知道是什么意思,希望各位能帮我解释一下。,第1张

其芦告老实就是程序设计的流程图,用于应用程序开发的蓝本,随便找个流程图看看就明白是什么意思了

说不太能说的明白,类似于棋谱一类的东西,上一步走什么友敬,下一步走什么

http://image.baidu.com/i?tn=baiduimage&ct=201326592&cl=2&lm=-1&fr=ala0&fmq=&pv=&ic=0&z=0&se=1&showtab=0&fb=0&width=&height=&face=0&word=java+%B3%CC%D0%F2%C9%E8%BC%C6%C1%F7%B3%CC%CD%BC&s=0#width=&height=&z=0&fb=0&ic=0&lm=-1&face=0

在百度陪升图片搜索

分类: 电脑/网络 >>程序设计 >>其他编程语言

解析:

import javax.swing.*

import java.awt.*

import java.awt.event.*

public class Calculator implements ActionListener

{

String s="",s1

double d1,d2

JFrame jf = new JFrame("小计算器by Graduate")

JTextField tf = new JTextField()

public void init()实现计算器界面

{

Container c=jf.getContentPane()

tf.setHorizontalAlignment(JTextField.RIGHT)文本框

c.add(tf,"North")

JPanel pn3 = new JPanel(new BorderLayout())

c.add(pn3,"Center")

JPanel pn2 = new JPanel()功能键界面(清除键和关闭键)

pn2.setLayout(new BorderLayout())

JPanel pn1 = new JPanel()运算界面

pn1.setLayout(new GridLayout(4,4))

pn3.add(pn2,"North")

pn3.add(pn1)

设置按钮

JButton b = new JButton("CLEAR")

b.setToolTipText("请按燃消斗清除键!")设置清零键

b.setForeground(Color.RED)设置字体颜色

b.setBackground(Color.YELLOW)设置背景色

b.addActionListener(this)

pn2.add(b,"Center")

b = new JButton("OFF")

b.setToolTipText("请按退出键!")设置off键,点击退出应用程序桥粗b.addActionListener(this)

b.setForeground(Color.RED)字体颜色

b.setBackground(Color.ORANGE)背景色

pn2.add(b,"East")

b = new JButton("1")add butten 1

b.addActionListener(this)

pn1.add(b)

b = new JButton("2")add butten 2

b.addActionListener(this)

pn1.add(b)

b = new JButton("3"皮磨)add butten 3

b.addActionListener(this)

pn1.add(b)

b = new JButton("+")add butten +

b.setForeground(Color.BLUE)设置字体颜色

b.addActionListener(this)

pn1.add(b)

b = new JButton("4")add butten 4

b.addActionListener(this)

pn1.add(b)

b = new JButton("5")add butten 5

b.addActionListener(this)

pn1.add(b)

b = new JButton("6")add button 6

b.addActionListener(this)

pn1.add(b)

b = new JButton("-")add button -

b.setForeground(Color.BLUE)设置字体颜色

b.addActionListener(this)

pn1.add(b)

b = new JButton("7")add button 7

b.addActionListener(this)

pn1.add(b)

b = new JButton("8")add button 8

b.addActionListener(this)

pn1.add(b)

b = new JButton("9")add button 9

b.addActionListener(this)

pn1.add(b)

b = new JButton("*")add button *

b.setForeground(Color.BLUE)设置字体颜色

b.addActionListener(this)

pn1.add(b)

b = new JButton("0")add button 0

b.addActionListener(this)

pn1.add(b)

b = new JButton(".")add button .

b.addActionListener(this)

pn1.add(b)

b = new JButton("=")add button =

b.setForeground(Color.RED)设置字体颜色

b.addActionListener(this)

pn1.add(b)

b = new JButton("\\")add button \

b.setForeground(Color.BLUE)设置字体颜色

b.addActionListener(this)

pn1.add(b)

jf.setSize(300,300)设置大小

jf.setVisible(true)设置为可视

}

处理按钮按下时的动作,进行相应的处理

public void actionPerformed(ActionEvent e)

{

String mand = e.getActionCommand()

tf.setText(tf.getText()+mand)

if(mand.equals("CLEAR")) 清零键 按下时返回初始状态

{

s1=null

s=""

tf.setText("")记录输入值的变量清空

}

else if(mand.equals("OFF")) System.exit(0)off键 关闭应用程序

else if(!mand.equals("*")&&!mand.equals("\\")

&&!mand.equals("+")&&!mand.equals("-")

&&!mand.equals("="))判断输入是否为数字

{

if(s1==null)判断输入是否为第一个

s1 = mand

else s1+=mand

d1 = new Double(s1).doubleValue()字符串型转换为双精度型,还原输入数字

try

{

if(s.equals("+")) d1 = d1+d2加法运算

else if(s.equals("-")) d1 = d2-d1减法运算

else if(s.equals("*")) d1 = d1*d2乘法运算

else if(s.equals("\\"))d1 = d2/d1除法运算

}

catch(Exception ex)

{

tf.setText("Error")错误显示"Error"

System.out.println(ex.getMessage())

}

}

else if(!mand.equals("=")) 判断输入是否为+ - * \

{

s = mand

s1 = null

d2 = d1

}

else输入=时,显示运算结果

{

tf.setText(tf.getText()+d1)

}

}

public static void main(String [] args)

{

new Calculator().init()

}

}

流程图如下:首先,你祥脊的JAVA程序是用来进行选手评分的。为保证公正性,所以一般都会以去掉一个最高分,在去掉一个最低分,求和算平均值的方法来算的。float[] score={8.5f,9.5f,8,7,9,8.7f,6.8f,10,7.9f,8.9f}score数组中,即为各个评委给出的的结果。芹册通过Arrays.sort(score)将数组由小到达排序,即为:float[] score={6.8f,7.0f,7.9f,8.0f,8.5f,8.7f,8.9f,9.0f,9.5f,10}之后用for循环求和,在求和过程中为去掉最低分,所以从索引j=1开始累加(数组索引由0开始)为去掉最高分嫌宴宏,加到索引j=score.length-1(数组个数-1)。此时for循环后,sum即为去掉最高分和最低分的求和了。之后的事情,相信你就明白了,我就不多说了。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12452014.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存