0

Java error

I am trying to take a inputed date from user and add 10 days to it but I keep get this error... (Assignment conversion not possible from type “java.lang.string” to type “java.until.calender”) Please help

8th Apr 2019, 12:43 AM
Jose Rodriguez
Jose Rodriguez - avatar
5 Antworten
+ 6
Can you please show us the code snippet so that we can suggest potential fixes? From the looks of it, you just need to cast your input to date.
8th Apr 2019, 12:48 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
I made this. It's correct, unless you want custom formatting. :3 import java.util.Scanner; import java.util.Calendar; import java.util.Date; public class TestProject { public static void main(String[] args){ Scanner date = new Scanner(System.in); System.out.println("Enter Date mm/dd/yyyy"); Calendar cal = Calendar.getInstance(); cal.setTime(new Date(date.nextLine())); cal.add(Calendar.DATE, 10); System.out.println("10 days later: " + cal.getTime()); } } Further reading: https://www.mkyong.com/java/java-date-and-calendar-examples/
8th Apr 2019, 1:24 AM
Fermi
Fermi - avatar
+ 1
date.nextLine() will return string value, you trying to assign it to variable with Calendar type. Here is correct way to do it https://stackoverflow.com/questions/5301226/convert-string-to-calendar-object-in-java
8th Apr 2019, 1:09 AM
Dima Makieiev
Dima Makieiev - avatar
0
import java.util.Scanner; import java.util.Calendar; public class TestProject { public static void main(String[] args){ Scanner date = new Scanner(System.in); System.out.println("Enter Date mm/dd/yyyy"); date.nextLine(); Calendar cal = date.nextLine(); cal.add(Calendar.DATE, 10); System.out.println("10 days later: " + cal.getTime());
8th Apr 2019, 12:51 AM
Jose Rodriguez
Jose Rodriguez - avatar
0
Thank you all
8th Apr 2019, 1:44 AM
Jose Rodriguez
Jose Rodriguez - avatar