Note that there are some explanatory texts on larger screens.

plurals
  1. POProgram doesn't run all the way through
    primarykey
    data
    text
    <p>So I'm trying to write a program for my computer programming class, it's supposed to print out a calendar for the month. I want my program to come up with the first day of the month without asking the person for the starting day, so I found an equation that'll do that and tried to use it in the program. It compiles fine, but when it reaches the part where it should start the equation and print out the calendar, the program just...stops. It stops running entirely and returns to the V:\JavaPrograms> command prompt thing.</p> <p>I can't figure out why this is happening. Here's the code:</p> <pre><code>import java.util.*; public class Lesson13p2_ThuotteEmily { public static void main(String args[]) { Scanner r=new Scanner(System.in); System.out.println("What year is it? "); int y=r.nextInt(); System.out.println("Please pick a month from the list below:"); System.out.println("\n1. January\n2. February\n3. March"); Scanner b=new Scanner(System.in); System.out.println("Enter your choice here by inputting the number next to the month: "); int m=b.nextInt(); int d=1, o; switch(m) { case 1: o=13; int n=d+2*o+(3*(o+1)/5)+y+(y/4)-(y/100)+(y/400)+2; if(n==1) { System.out.println("Here is your calendar for January, "+y+", which starts on a Sunday."); System.out.println("\t\tJanuary\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=31;k++) { System.out.print((++j)+"\t"); } System.out.println(""); } ++j; } else if(n==2) { System.out.println("Here is your calendar for January, "+y+", which starts on a Monday."); System.out.println("\t\tJanuary\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=31;k++) { System.out.print((++j)+"\t\t"); } System.out.println(""); } ++j; } else if(n==3) { System.out.println("Here is your calendar for January, "+y+", which starts on a Tuesday."); System.out.println("\t\tJanuary\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=31;k++) { System.out.print((++j)+"\t\t\t"); } System.out.println(""); } ++j; } else if(n==4) { System.out.println("Here is your calendar for January, "+y+", which starts on a Wednesday."); System.out.println("\t\tJanuary\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=31;k++) { System.out.print((++j)+"\t\t\t\t"); } System.out.println(""); } ++j; } else if(n==5) { System.out.println("Here is your calendar for January, "+y+", which starts on a Thursday."); System.out.println("\t\tJanuary\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=31;k++) { System.out.print((++j)+"\t\t\t\t\t"); } System.out.println(""); } ++j; } else if(n==6) { System.out.println("Here is your calendar for January, "+y+", which starts on a Friday."); System.out.println("\t\tJanuary\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=31;k++) { System.out.print((++j)+"\t\t\t\t\t\t"); } System.out.println(""); } ++j; } else if(n==7) { System.out.println("Here is your calendar for January, "+y+", which starts on a Saturday."); System.out.println("\t\tJanuary\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=31;k++) { System.out.print((++j)+"\t\t\t\t\t\t\t"); } System.out.println(""); } ++j; } case 2: if((y%100!=0||y%400==0)&amp;&amp;y%4==0) { o=14; int n=d+2*o+(3*(o+1)/5)+y+(y/4)-(y/100)+(y/400)+2; if(n==1) { System.out.println("Here is your calendar for February, "+y+", which starts on a Sunday and is a leap year."); System.out.println("\t\tFebruary\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=29;k++) { System.out.print((++j)+"\t"); } System.out.println(""); } ++j; } else if(n==2) { System.out.println("Here is your calendar for February, "+y+", which starts on a Monday and is a leap year."); System.out.println("\t\tFebruary\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=29;k++) { System.out.print((++j)+"\t\t"); } System.out.println(""); } ++j; } else if(n==3) { System.out.println("Here is your calendar for February, "+y+", which starts on a Tuesday and is a leap year."); System.out.println("\t\tFebruary\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=29;k++) { System.out.print((++j)+"\t\t\t"); } System.out.println(""); } ++j; } else if(n==4) { System.out.println("Here is your calendar for February, "+y+", which starts on a Wednesday and is a leap year."); System.out.println("\t\tFebruary\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=29;k++) { System.out.print((++j)+"\t\t\t\t"); } System.out.println(""); } ++j; } else if(n==5) { System.out.println("Here is your calendar for February, "+y+", which starts on a Thursday and is a leap year."); System.out.println("\t\tFebruary\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=29;k++) { System.out.print((++j)+"\t\t\t\t\t"); } System.out.println(""); } ++j; } else if(n==6) { System.out.println("Here is your calendar for February, "+y+", which starts on a Friday and is a leap year."); System.out.println("\t\tFebruary\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=29;k++) { System.out.print((++j)+"\t\t\t\t\t\t"); } System.out.println(""); } ++j; } else if(n==7) { System.out.println("Here is your calendar for February, "+y+", which starts on a Saturday and is a leap year."); System.out.println("\t\tFebruary\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=29;k++) { System.out.print((++j)+"\t\t\t\t\t\t\t"); } System.out.println(""); } ++j; } } else { o=14; int n=d+2*o+(3*(o+1)/5)+y+(y/4)-(y/100)+(y/400)+2; if(n==1) { System.out.println("Here is your calendar for February, "+y+", which starts on a Sunday."); System.out.println("\t\tFebruary\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=28;k++) { System.out.print((++j)+"\t"); } System.out.println(""); } ++j; } else if(n==2) { System.out.println("Here is your calendar for February, "+y+", which starts on a Monday."); System.out.println("\t\tFebruary\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=28;k++) { System.out.print((++j)+"\t\t"); } System.out.println(""); } ++j; } else if(n==3) { System.out.println("Here is your calendar for February, "+y+", which starts on a Tuesday."); System.out.println("\t\tFebruary\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=28;k++) { System.out.print((++j)+"\t\t\t"); } System.out.println(""); } ++j; } else if(n==4) { System.out.println("Here is your calendar for February, "+y+", which starts on a Wednesday."); System.out.println("\t\tFebruary\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=28;k++) { System.out.print((++j)+"\t\t\t\t"); } System.out.println(""); } ++j; } else if(n==5) { System.out.println("Here is your calendar for February, "+y+", which starts on a Thursday."); System.out.println("\t\tFebruary\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=28;k++) { System.out.print((++j)+"\t\t\t\t\t"); } System.out.println(""); } ++j; } else if(n==6) { System.out.println("Here is your calendar for February, "+y+", which starts on a Friday."); System.out.println("\t\tFebruary\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=28;k++) { System.out.print((++j)+"\t\t\t\t\t\t"); } System.out.println(""); } ++j; } else if(n==7) { System.out.println("Here is your calendar for February, "+y+", which starts on a Saturday."); System.out.println("\t\tFebruary\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=28;k++) { System.out.print((++j)+"\t\t\t\t\t\t\t"); } System.out.println(""); } ++j; } } case 3: o=3; int n=d+2*o+(3*(o+1)/5)+y+(y/4)-(y/100)+(y/400)+2; if(n==1) { System.out.println("Here is your calendar for March, "+y+", which starts on a Sunday."); System.out.println("\t\tMarch\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=31;k++) { System.out.print((++j)+"\t"); } System.out.println(""); } ++j; } else if(n==2) { System.out.println("Here is your calendar for March, "+y+", which starts on a Monday."); System.out.println("\t\tMarch\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=31;k++) { System.out.print((++j)+"\t\t"); } System.out.println(""); } ++j; } else if(n==3) { System.out.println("Here is your calendar for March, "+y+", which starts on a Tuesday."); System.out.println("\t\tMarch\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=31;k++) { System.out.print((++j)+"\t\t\t\t"); } System.out.println(""); } ++j; } else if(n==4) { System.out.println("Here is your calendar for March, "+y+", which starts on a Wednesday."); System.out.println("\t\tMarch\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=31;k++) { System.out.print((++j)+"\t\t\t\t\t"); } System.out.println(""); } ++j; } else if(n==5) { System.out.println("Here is your calendar for March, "+y+", which starts on a Thursday."); System.out.println("\t\tMarch\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=31;k++) { System.out.print((++j)+"\t\t\t\t\t"); } System.out.println(""); } ++j; } else if(n==6) { System.out.println("Here is your calendar for March, "+y+", which starts on a Friday."); System.out.println("\t\tMarch\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=31;k++) { System.out.print((++j)+"\t\t\t\t\t\t"); } System.out.println(""); } ++j; } else if(n==7) { System.out.println("Here is your calendar for March, "+y+", which starts on a Saturday."); System.out.println("\t\tMarch\nSun\tMon\tTues\tWed\tThurs\tFri\tSat\n------------------------------------------------------------------------------"); int j = 0, k=0; while(j&lt;=4) { for(k=1;k&lt;=31;k++) { System.out.print((++j)+"\t\t\t\t\t\t\t"); } System.out.println(""); } ++j; } } } } </code></pre> <p>Also, I tried using just a regular if statement first, but it didn't work.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload