In: Computer Science
Write a java program that will ask for a Star Date and then
convert it into the corresponding
Calendar date. without using array and methods.
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Scanner;
public class StardateToDate {
public static void main(String[] args) {
// TODO Auto-generated method stub
Calendar d=new GregorianCalendar();
Scanner src=new Scanner(System.in);
float Sdate;
System.out.println("Enter Star date:");
Sdate=src.nextFloat();
int year=2323+(int)Sdate/1000;
d.set(d.YEAR, year);
int n=365;
if(year % 4 == 0)
{
if( year % 100 == 0)
{
if ( year % 400 == 0)
n = 366;
}
else
n=366;
}
float Sd=Sdate-((int)Sdate/1000)*1000;
System.out.println(Sd);
int Cd=(int) ((Sd*n)/1000);
System.out.println(Cd);
d.add(d.DAY_OF_YEAR, Cd);
System.out.println(d.get(d.DAY_OF_MONTH)+" "+d.get(d.MONTH)+" "+d.get(d.YEAR));
src.close();
}
}