This is another code(below) from my CS Assignment. Here, I have to build a program that calculates how many days have you lived and how many hours you slept. I have seem to got the question but I get an error with Scanner sc = new Scanner(System.in);
Here is the code:
import java.util.*; public class DaysLived { public static void main(String args [] ){ Scanner sc = new Scanner(System.in); int by; int cy; int mb; int mc; int db; int dc; int sleep; int aliveday; aliveday = ((cy-by)*365)+((mc-mb)*30)+(dc-db); sleep = aliveday*8; System.out.println("What's the date today?"); System.out.print ("Year: "); cy = sc.nextInt (); System.out.print ("Month: "); mc = sc.nextInt (); System.out.print ("Day: "); dc = sc.nextInt (); System.out.println ("Great, when were you born?"); System.out.print ("Year: "); by = sc.nextInt (); System.out.print ("Month: "); mb = sc.nextInt (); System.out.print ("Day: "); db = sc.nextInt (); System.out.println ("You have lived " + aliveday + "and you have slept " + sleep + " hours."); } }
So, I am trying to get an input from the user.
What should I do?
Thanks in advance.