| | |
Calendar Project for school
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Aug 2008
Posts: 208
Reputation:
Solved Threads: 13
ok, so, we have to make a program that displays the date 100 days from today, the day you were born, and the date 10,000 days after your birth date. I've done all that, but i want to take it a step further, i want the user to be able to input the number of days from today that he/she wishes to know the date of (if that makes any sense at all...). Here's what the part of the code i'm working on looks like:
I'm using Bluej and it says, "incompatible types - found java.lang.String but expected int"
I'm at a loss. i don't have any idea what to do. any advise would be great. and yes, i know there are no end brackets.
Java Syntax (Toggle Plain Text)
import java.util.GregorianCalendar; import java.lang.String; import java.util.Scanner; public class calendarProjectTest { public static void main(String[] args) { GregorianCalendar cal = new GregorianCalendar(); //declare today's date GregorianCalendar myBirthday = new GregorianCalendar(1992, GregorianCalendar.JUNE, 9); //declare my birthday System.out.println("Please enter a number greater than 0:"); Scanner keyboard = new Scanner(System.in); String number = keyboard.next(); int value = number; cal.add(GregorianCalendar.DAY_OF_MONTH, number);
I'm using Bluej and it says, "incompatible types - found java.lang.String but expected int"
I'm at a loss. i don't have any idea what to do. any advise would be great. and yes, i know there are no end brackets.
Last edited by llemes4011; Aug 24th, 2008 at 4:08 pm.
keyboard.next(); returns a string, not an int, so int value = number is trying to assign a string value to an int type. try putting this instead:
int value = Integer.parseInt( number ); My site, random PM's from people I haven't hear from before will be DELETED
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "-Albert Einstein
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "-Albert Einstein
![]() |
Similar Threads
- trojans...now nothing opens and I get a paint can't open error (Viruses, Spyware and other Nasties)
- Newbie to Forum and IT (IT Professionals' Lounge)
Other Threads in the Java Forum
- Previous Thread: Run-time GUI systems opinions
- Next Thread: Day finder
Views: 973 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for Java
-xlint android animated api apple applet application arguments array arrays automation binary blackberry block bluetooth chat class classes client code component database detection developmenthelp draw eclipse encode error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer iphone j2me j2seprojects java javac javaprojects jmf jni jpanel julia lego linux list loop loops mac map method methods mobile netbeans newbie number object online oracle os page print problem program programming project recursion scanner screen server set singleton size sms socket sort sql string swing template test textfields threads time title transfer tree tutorial-sample update windows working





