JAVA经典实用程序代码

2019-06-17 16:11

1百分制分数到等级分数 package pm;

public class SwitchTest { //编写程序,实现从百分制分数到等级分数的转换 // //>=90 A // 80~89 B // 70~79 C // 60~69 D // <60 E public static void main(String[] args) { int s=87; switch(s/10){

case 10 :System.out.println(\ case 9 :System.out.println(\ case 8 :System.out.println(\ case 7 :System.out.println(\ case 6 :System.out.println(\ default :System.out.println(\ } } }

2成法口诀阵形 package pm;

public class SwitchTest{ public static void main(String[] args){ for(int i=1;i<=9;i++){ for(int j=1;j<=i;j++){ System.out.print(j+\ } System.out.println(); }

} }

3华氏和摄氏的转换法

package pm;

import java.util.Scanner; public class SwitchTest { public static void main(String[] args) { Scanner sc=new Scanner(System.in); while (true) { System.out.println(\请输入要转换的温度类型:C 或 F\ String s = sc.next().trim(); if (\ //做摄氏向华摄的转换 System.out.println(\请输入要转换摄氏的温度:..\ double db = sc.nextDouble(); double db2 = (db * 9 / 5) + 32; System.out.println(\对应的华氏温度:\ } else if (\ //做华摄向摄氏的转换 System.out.println(\请输入要转换华氏的温度:..\ double db = sc.nextDouble(); double db2 = (db - 32) * 5 / 9; System.out.println(\对应的摄氏温度:\ }else if(\ break; } } } }

package pm;

import java.util.Scanner;

public class SwitchTest{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); boolean flag=true; while (flag) { System.out.println(\请输入要转换的温度,如:50c或100f\ String str = sc.nextLine().trim(); if (str.endsWith(\ //做摄氏向华摄的转换 30c String st = str.substring(0, str.length() - 1); double db = Double.parseDouble(st);//[0,2) //2 double db=Double.valueOf(st).doubleValue(); double db2 = (db * 9 / 5) + 32; System.out.println(\对应的华氏温度:\ } else if (str.endsWith(\ //做华摄向摄氏的转换 String st = str.substring(0, str.length() - 1); double db = Double.parseDouble(st);//[0,2) //2 double db=Double.valueOf(st).doubleValue(); double db2 = (db - 32) * 5 / 9; System.out.println(\对应的摄氏温度:\ }else if(\ flag=false; } } } }

4三个数的最大数 package pm;

public class SwitchTest { public static void main(String[] args) { int a=1,b=2,c=3,d=0; d=a>b?a:b;

d=a>b?(a>c?a:c):(b>c?b:c); System.out.println(\最多数为:\ } }

5简单计算器的小程序

package one;

import java.awt.BorderLayout; import java.awt.GridLayout;

import java.awt.event.ActionEvent; import java.awt.event.ActionListener;

import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField;

public class Jsq implements ActionListener { private JFrame frame; private JButton[] bus; private JTextField jtx; private JButton bu; private char[] strs; private String d_one = \ private String operator; public static void main(String[] args) { new Jsq(); }

/* 利用构造进行实例化 */ public Jsq() { frame = new JFrame(\计算器\ jtx = new JTextField(14); bus = new JButton[16]; strs = \ for (int i = 0; i < 16; i++) { bus[i] = new JButton(strs[i] + \ bus[i].addActionListener(this); } bu = new JButton(\ bu.addActionListener(this); init(); }

/* GUI 初始化 */ public void init() { JPanel jp1 = new JPanel(); jp1.add(jtx); jp1.add(bu); frame.add(jp1, BorderLayout.NORTH); }

/* 事件的处理 */

public void actionPerformed(ActionEvent arg0) { /*获取输入字符*/ String conn = arg0.getActionCommand(); /*清除计算器内容*/ if (\

JPanel jp2 = new JPanel();

jp2.setLayout(new GridLayout(4, 4)); for (int i = 0; i < 16; i++) { jp2.add(bus[i]); }

frame.add(jp2, BorderLayout.CENTER);

frame.pack();

frame.setLocation(300, 400); frame.setVisible(true);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


JAVA经典实用程序代码.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:电力系统分析实验指导书(参考数据)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: