Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Write a java pregram: Help with methods
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


James Huber
Write a java pregram: Help with methods
1 Answer(s)      a year and 2 months ago
Posted in : Java Beginners


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)); 

}
}

Advertisement
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 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
write a program to demonstrate wrapper class and its methods......
write a program to demonstrate wrapper class and its methods......  write a program to demonstrate wrapper class and its methods
Advertisements
Java methods
Java methods  What are the differences between == and .equals
methods type - Java Beginners
methods type in Java  Give me an example programs of methods types in Java
Java overloaded methods
Java overloaded methods  Can overloaded methods can also be overridden
java object class methods
java 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 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
to create a java class and methods
to 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 Questions
java 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 Beginners
Overloaded 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
java methods - Java Beginners
java 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
Methods in Java - Java Beginners
Methods 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 Beginners
String 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
list of predeined methods and use java
list of predeined methods and use java  I need list of predefined methods in java like reverse,compare,tostring, etc
Java Methods Problem - Java Beginners
Java 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 Beginners
Java 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 file with many methods - Ajax
java 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
write a java program
write a java program  write a program to print '*' in a circular form
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
How to write Java Program
How to write Java Program  how to write a program to find average of 5 student marks
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 programm using java
write a programm using java  print the following using java programming
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
What are the methods in Object? - Java Beginners
What 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
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
write the java program?
write the java program?  1 11 121 1331 14641 15101051
Write java program?
Write java program?  1 11 121 1331 14641 15101051
 

 

 

DMCA.com