十个JAVA程序代码.doc
文本预览下载声明
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(对应的摄氏温度: + Math.round(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 (str.endsWith(c) || str.endsWith(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;
S
显示全部