JAVA经典实用程序代码 下载本文

内容发布更新时间 : 2024/5/28 3:14:14星期一 下面是文章的全部内容请认真阅读。

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;