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("A");break;
case 9 :System.out.println("A");break;
case 8 :System.out.println("B");break;
case 7 :System.out.println("c");break;
case 6 :System.out.println("D");break;
default :System.out.println("E");break;
}
}
}
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+"*"+i+"="+(i*j)+"\t");
}
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 ("c".equalsIgnoreCase(s)) {
//做摄氏向华摄的转换
System.out.println("请输入要转换摄氏的温度:..");
double db = sc.nextDouble();
double db2 = (db * 9 / 5) + 32;
System.out.println("对应的华氏温度:" + db2 + "F");
} else if ("f".equalsIgnoreCase(s)) {
//做华摄向摄氏的转换
System.out.println("请输入要转换华氏的温度:..");
double db = sc.nextDouble();
double db2 = (db - 32) * 5 / 9;
System.out.println("对应的摄氏温度:" + und(db2) + "C");
}else if("exit".equalsIgnoreCase(s)){
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 (dsWith("c") || dsWith("C")) {
//做摄氏向华摄的转换 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("对应的华氏温度:" + db2 + "F");
} else if (dsWith("f") || dsWith("F")) {
//做华摄向摄氏的转换
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("对应的摄氏温度:" + und(db2) + "C");
}else if("exit".equalsIgnoreCase(str)){
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("最多数为:"+d);
}
}
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("计算器");
java switch case string jtx = new JTextField(14);
bus = new JButton[16];
strs = "789/456*123-0.+=".toCharArray();
for (int i = 0; i < 16; i++) {
bus[i] = new JButton(strs[i] + "");
bus[i].addActionListener(this);
}
bu = new JButton("C");
bu.addActionListener(this);
init();
}
/* GUI 初始化 */
public void init() {
JPanel jp1 = new JPanel();
jp1.add(jtx);
jp1.add(bu);
frame.add(jp1, BorderLayout.NORTH);
JPanel jp2 = new JPanel();
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论