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
Related Tutorials/Questions & Answers:
Write a java pregram: Help with methodsWrite 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 methodsJava methods What are the differences between == and .equals
java object class methodsjava object class methods What are the
methods in Object class? There are lots of
methods in object class.
the list of some
methods are as-
clone
equals
wait
finalize
getClass
hashCode
notify
notifyAll
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 javaabstract
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
to create a java class and methodsto create a
java class and methods How to create a
java class... it with
methods that can be used to reverse a list & append two lists.Also to comment on whether the dsign ade has led to make
methods for append
java methods - Java Interview Questionsjava methods what are native
methods? how and when they are use? Hi friend,
The ability to
write just one set of code in
Java... C code into your
Java application.
The steps to creating native
methods Overloaded methods - Java BeginnersOverloaded methods
Write two overloaded
methods that return the average of an array with the following headers:
a) public static int average(int[] array)
b) public static double average(double[] array)
Hi Friend
methodsmethods PrintStream class has two formatting
methods,what
methodsmethods PrintStream class has two formatting
methods,what
methodsmethods PrintStream class has two formatting
methods,what
Methods in Java - Java BeginnersMethods in Java Hello.
Currently i am involved in a group project and we have each been given a specific part of code to create our joint programI... mean, could someone
help me please?
Thanks!
Hi Friend,
Try
String Methods - Java BeginnersString Methods Greetings RoseIndia Team;
Thank you for your prompt response to my question. I have one other question requiring your assistance. I have to
write a program that accepts multiple sentences (at least 2
java methods - Java Beginnersjava methods Hello,
what is difference between a.length() and a.length;
kindly can anybody explain.
thanks for your time Hi Friend,
length() is used to find the length of string whereas length is used
How to write in File in JavaHow 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 prgramwrite 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 file with many methods - Ajaxjava file with many methods I have to send response to a
java file where there are many
methods and I have to call one of them by passing parameter .How can I do
Java Methods Problem - Java BeginnersJava Methods Problem I have to
write a program that has three types of pie. Apple, which is the default pie, cherry and pumpkin. I then have to ask the customer what type of pie they like and store it in kind and then ask
Java Methods Problem - Java BeginnersJava Methods Problem I have to
write a program that has three types of pie. Apple, which is the default pie, cherry and pumpkin. I then have to ask the customer what type of pie they like and store it in kind and then ask
Java write to fileJava 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 JavaHow 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
What are the methods in Object? - Java BeginnersWhat are the
methods in Object? Hi,
What are the
methods in Object? Give example of
methods in Object.
Thanks
Hello,
There are lot of method in object class some of are as follows
toString();
wait
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
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.
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 codehelp 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 codehelp 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 JAVAWRITE 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
WRITE A PROGRAM IN JAVAWRITE A PROGRAM IN JAVA
Write program which accepts five students id,name,age,department,courses, taken and its grade.
a. calculate its GPA
. display all student information in ascending order
write program - Java Beginnerswrite program
write a
java program that will read the values...]);
}
System.out.println();
}
}
}
For more information on
java visit to :
http://www.roseindia.net/
java/beginners/
Thanks
notify and notifyAll methods - Java Beginnersnotify and notifyAll methods I need a program demonstrating the
methods of notify and notifyAll. please can you suggest me a way out. visit this link
http://www.java-samples.com/showtutorial.php?tutorialid=306
using class and methods - Java Beginnersusing class and methods Sir,Plz
help me to
write this below pgm. here is the question:
Assume a table for annual examination results for 10 students.
write a program to read the data and determine the following:
a) Total
creating class and methods - Java Beginners of the Computers.
This class contains following
methods,
- Constructor method... quantity;
public Computer(String n,int s,int sp,String m,double p,int
q){
name=n;
size=s;
speed=sp;
make=m;
price=p;
quantity=
q;
}
public String
write a program - Java Beginnerswrite a program 1.
write a program that reads a string composed of 6 words then generate and print a word composed of the first letters of the 6 words. Hi friend,
Code to solve the problem :
class FirstLetter