Write a java pregram: Help with methods
Write a Java method that returns the number of days in a year using the following header:
public static int numberOfDaysInAYear (int year)
Write a Java program that uses your method and displays the number of days in a year from 2013 to 2025 as a table. Include a title line for your table that looks like:
YEAR #DAYS
This is what i have so far and i have no clue what to do next
public class Daysinayear {
public static void main(String[] args) {
System.out.println(years)
}
public static int numberOfDaysInAYear (int years){
int numberofdays=0;
for(years=2013;years<=2025;years++)
if(isLeapYear(years))
numberofdays= numberofdays + 366;
else
numberofdays= numberofdays +365;
return numberofdays;
}
public static boolean isLeapYear(int year) {
return isLeapYear = ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0));
}
}
View Answers
October 9, 2013 at 12:57 PM
Hi,
Here is the example code:
package net.roseindia;
import java.util.*;
public class DaysInYear {
static int getDaysinYear(int year) {
int days = 0;
Calendar fromDate = new GregorianCalendar();
Calendar toDate = new GregorianCalendar();
fromDate.set(year, 1, 1);
toDate.set(year, 12, 31);
long diff = toDate.getTimeInMillis() - fromDate.getTimeInMillis();
float dayCount = (float) diff / (24 * 60 * 60 * 1000);
days = (int) dayCount;
return days;
}
public static void main(String[] args) {
for (int years = 2013; years <= 2025; years++) {
System.out.println("No of days in the Year: " + years + " is: "
+ DaysInYear.getDaysinYear(years));
}
}
}
Read more tutorials at Java Date Examples.
Thanks
Ads
Related Tutorials/Questions & Answers:
Write a java pregram: Help with methods
Write a
java pregram:
Help with methods
Write a
Java method that returns the number of days in a year using the following header:
public static int numberOfDaysInAYear (int year)
Write a
Java program that uses your method
Advertisements
Java methods
Java methods What are the differences between == and .equals
factory methods in java?
factory
methods in
java? what are factory
methods in
java?
Hi Friend,
Factory
methods are static
methods that return an instance of the native class like Pattern.compile(), Calendar.getInstance
abstract methods in java
abstract
methods in java what is abstract
methods in java.give better examples for understanding
Hi Friend,
Please visit the following link:
http://www.roseindia.net/
java/master-
java/abstract-class.shtml
Thanks
methods
methods PrintStream class has two formatting
methods,what
methods
methods PrintStream class has two formatting
methods,what
methods
methods PrintStream class has two formatting
methods,what
How to write in File in Java
How to
write in File in Java Hi,
How to
write in File in
Java. Please suggest and give example of this program.
thanks
write java prgram
write java prgram
write java program to offer a menu which contains 3 choices to make calculation on 3 shapes.use method for each calculation
Java write to file
Java write to file How to
write to a file in
Java?
Is there any good example code here?
Thanks
Hi,
Java is one of the best... files.
You can easily use the the FileWriter and BufferedWriter to
write data
How to write in File in Java
How to
write in File in Java Hi,
How to
write in File in
Java... to
write in File of
Java Program... the (BufferedReader) constructor. So that we
write some data suing
Non-virtual Methods in Java - java tutorials
: #000000;
}
Non Virtual
Methods in
Java
Lets see the concept of virtual
methods, a virtual function is
function whose behavior can not be overridden... hierarchy.
In
Java programming language all the
methods are virtual, i.e.
Write a java application program........?
Write a
java application program........? Welcome every One :
I have
Q in
Java?
Q :
Write a
java application program that reads 20 integer numbers input by the user and prints how many numbers > 100 and how many numbers
How to Write to file in Java?
How to
Write to file in
Java? How to
Write to file in
Java Program?
Hi,
For writing a file in
Java, we need some classes from Java.IO... the Examples of How to
write to File in
Java Program:
WriteToFileExample.java
import
Write a program in java...
Write a program in
java... Hi, friends
Please, can you
help me?
Q1:
Write a program in
java to simulate a calculator. Your program should take two... to enter an integer number.
Write a program in
java to find the factorial
help to write java code
help to
write java code
write a full code to produce a system will calculate all items to get total carry-marks which are 60 marks. and get sum of assignment 1,assignment 2, midterms-test and lave work to get total marks
help to write java code
help to
write java code
write a full code to produce a system will calculate all items to get total carry-marks which are 60 marks. and get sum of assignment 1,assignment 2, midterms-test and lave work to get total marks
WRITE A PROGRAM IN JAVA
WRITE A PROGRAM IN JAVA How do I
write a program in
Java, have the program display a message with your name in it and a number (Hello john Smith!1) The number must increment from zero to nine, or decrement fron nine to zero. You