RichardSmith
New member
המשך שיעורי תכנות!
כן, כן, אני יודע שכולכם פשוט השתוקקתם לרגע. (קצת שכחתי לעלות שבוע שעבר את הקוד...
) אז הנה הקוד של שבוע שעבר:
כן, כן, אני יודע שכולכם פשוט השתוקקתם לרגע. (קצת שכחתי לעלות שבוע שעבר את הקוד...

import java.util.Scanner; public class zeller { public static void main(String[] args) { // create a Scanner object to read input from the screen Scanner input = new Scanner( System.in); int m, //month d1, //day y, //year c1, //century a,b,c,d,r; //help verbs System.out.println("Please master, give me a date!"); System.out.println("state it by month, day, year."); m = input.nextInt(); d1 = input.nextInt(); y = input.nextInt(); c1 = y/100; y=y%100; m = (m + 9)% 12 + 1; y = y - m / 11; a=(13*m-1)/5; b=y/4; c=c1/4; d = a + b + c + d1 + y -2*c1; r=d%7; r+=7; r=r/7+1; switch(r){ case 1: System.out.println("It is a Sunday, Sir."); case 2: System.out.println("It is a Monday, Sir."); case 3: System.out.println("It is a Tuesday, Sir."); case 4: System.out.println("It is a Wednesday, Sir."); case 5: System.out.println("It is a Thursday, Sir."); case 6: System.out.println("It is a Friday, Sir."); case 7: System.out.println("It is a Saturday, Sir."); } } }
הקוד מקבל תאריך ומחשב את היום בשבוע שהתאריך "נפל" עליו. די מדליק, הא?