I am trying to make a program that user is able to enter a date like: 28 -03 - 2014
.
This and the program reads that, gives the date of tomorrow like: 29 - march - 2014
. The program must check about:
-
-
Here is my code!
public String month()
{
int month = 0;
switch(month){
case 1 :monthString = " Janauri";
break;
case 2: monthString = "February"
.......
ublic String dateOfTomorrow(int day, int month, int year)
{
String Date = day+ "-" + month+ "- " + year;
day++;
if(day > totalDaysInMonth(month));
{// new month
day = 1;
month++;
if(month > 12)
{//new year
month= 1;
year ++;
}
}
return Date;
}
private boolean totalDaysInMonth(int day)
{
if( day >= 1 && day < 31)
{
return true;
}
else {
return false;
}
}
public void actionPerformed(ActionEvent e)
{
for ( int i = 1; i<31;);
String s = tf.getText();
if ( e.getSource() == b1)
{
l2.setText(s);
}
else if (e.getSource ()== b2)
{
l2.setText(monthString);
}
}
I think your problem is in this loop:
for ( int i = 1; i<31;);
which will never end. Remove that empty loop or change it to:
for ( int i = 1; i<31;i++);
I don't really understand what you mean by 1/2 stack. But if you make a string of some variables
String Date = day + "-" + month + "-" + year;
and then change the variables it doesn't have any effect on the string. So you will still get the same date back.
And a tip for better readability makes your variables camel cased. So instead of Date call it date.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.