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:

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.

Recommended Answers

All 2 Replies

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 );

awesome, thanks, it works perfectly now. Now i just have to make the code more flexible, for lack of a better word >.< hahaha

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.