网站大量收购闲置独家精品文档,联系QQ:2885784924

第三章[类的方法].ppt

  1. 1、本文档共91页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
第三章[类的方法]

第3章 类的方法;目录;3.1 方法的控制流程;3.1.1 if选择结构;if-else语句的特殊形式 if (boolean expression) { //statement1; } else if (boolean expression) { //statement2; } else if (boolean expression){ //statement; } … else { //statement; } ;例3-1 计算每个月的天数(暂不考虑闰年) static int daysInMonth(int month) { if (month == 2) return(28); else if ((month==4)||(month==6)||(month==9)|| (month==11)) return(30); else return(31); } ;输入一个年份,判断它是不是闰年。 闰年: 能被4整除但不能被100整除,或者能被400整除。 import java.io.*; public class LeapTest { public static void main(String[ ] args) throws IOException{ int year; boolean IsLeapYear; System.out.println(Enter the year:); BufferedReader in =new BufferedReader( new InputStreamReader(System.in)); year=(new Integer(in.readLine( ))).intValue( ); ; IsLeapYear=((year%4==0 year%100 != 0) || (year%400 == 0)); if (IsLeapYear) { System.out.print(year); System.out.println( is a leap year); } else { System.out.print(year); System.out.println( is not a leap year); } } };输入两个整数比较大小 import java.io.*; public class ex3_2 { public static void main(String[ ] args) throws IOException { int x, y; BufferedReader in = new BufferedReader( new InputStreamReader(System.in)); System.out.println(Enter x and y:); x=(new Integer(in.readLine( ))).intValue( ); y=(new Integer(in.readLine( ))).intValue( ); if (x!=y) if (xy) System.out.println(xy); else System.out.println(xy); else System.out.println(x=y); } };以条件运算符代替if-else例子: if (ab) System.out.println(The larger one is: +a); else System.out.println(The larger one is: +b); 用条件运算符重写: System.out.println(The larger one is: + (ab)?a:b); ;已知一个学生的分数,给出其分数等级。90-100分为A级;80-89分为B级;70-79分为C级;60-69分为D级;0-59分为E级 public class IfElseDemo

文档评论(0)

wuyoujun92 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档