南邮JAVA语言程序设计作业_南京邮电大学java程序设计作业在线编程第三次作业...

importjava.util.Scanner;/*** @Author liguo

* @Description 从键盘上读入一个百分制成绩x(0 < = x < = 100),

* 将其转换为等级制成绩输出。本题在C语言和Java语言中要求使用switch分支实现。

* 等级制成绩(百分制成绩)

* A(90<=x<=100)

* B(80<=x<90)

* C(70<=x<80)

* D(60<=x<70)

* E(0<=x<60)

* @Data 2018-04-03*/

public classMain {static void judge(intmark) {char degree = 'A';int temp = mark / 10;if (temp >= 0 && temp < 6)

degree= 'E';if (temp == 6)

degree= 'D';if (temp == 7)

degree= 'C';if (temp == 8)

degree= 'B';if (temp == 9 || temp == 10)

degree= 'A';

System.out.println( mark+ "--" +degree );

}public static voidmain(String[] args) {inttemp;

Scanner in= newScanner( System.in );int x =in.nextInt();

temp= x / 10;if (temp >= 0 && temp < 6)

temp= 5;switch(temp) {case 5:

judge( x );break;case 6:

judge( x );break;case 7:

judge( x );break;case 9:

judge( x );break;case 10:

judge( x );break;

}

}

}

用if语句求解分段函数 得分:10 / 10

importjava.util.Scanner;/*** @Author liguo

* @Description分段函数求解:输入 x ,计算并输出 y 的值:

* y=x+100 ( 当 x < 20)

* y= x ( 当 2 0 ≤ x ≤ 100)

* y=x-100 ( 当 x > 100)

* @Data 2018-04-03*/

public classMain {public static voidmain(String[] args) {doublex, y;

Scanner in= newScanner( System.in );

x=in.nextDouble();if (x < 20)

y= x + 100;else if (x >= 20 && x <= 100)

y=x;elsey= x - 100;

System.out.printf("x=%.2f,y=%.2f", x, y );

}

}2-2 混合类型数据格式化输入 得分:10 / 10

importjava.util.Scanner;/*** @Author liguo

* @Description 输入在一行中顺序给出浮点数1、整数、字符、浮点数2,其间以1个空格分隔。

* 输入描述

* 输入在一行中顺序给出浮点数1、整数、字符、浮点数2,其间以1个空格分隔。

* 输出描述

* 在一行中按照字符、整数、浮点数1、浮点数2的顺序输出,其中浮点数保留小数点后2位。

* @Data 2018-04-03*/

public classMain {public static voidmain(String[] args) {

Scanner in= newScanner( System.in );double d1 =in.nextDouble();int i =in.nextInt();

String s=in.next();char c = s.charAt( 0);double d2 =in.nextDouble();

System.out.printf("%c %d %.2f %.2f", c, i, d1, d2 );

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值