ให้เขียนลำดับ statement ใหม่ โดยให้เปลี่ยนจาก if เป็น if-else เพียงอันเดียว
if (year % 4==0)
System.out.print(year+"is a leap year.");
if(year % 4 !=0)
{
year = year +4 - year % 4;
System.out.print(year+"is the next leap year.");
}
Answer...
if (year % 4==0){
System.out.print(year+"is a leap year.");
if(year % 4 !=0)
}else{
year = year +4 - year % 4;
System.out.print(year+"is the next leap year.");
}
source : Programming and problem solving with Java
Nell Dale and Chip Weems. -- 2nd ed. page 270
ISBN-13 : 978-0-7637-3402-2
ไม่มีความคิดเห็น:
แสดงความคิดเห็น