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



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

Have Programming Question? Ask it here!
 
 
 


James Huber
Write a java pregram: Help with methods
1 Answer(s)      10 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
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 Java Program
How to write Java Program  how to write a program to find average of 5 student marks
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 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 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
Write java program?
Write java program?  1 11 121 1331 14641 15101051
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 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
why we use constructors instead of methods in java?
why we use constructors instead of methods in java?   why we use constructors instead of methods in java
Why doesn't Java allow overriding of static methods?
Why doesn't Java allow overriding of static methods?  Why doesn't Java allow overriding of static methods
notify and notifyAll methods - Java Beginners
notify 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
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
using class and methods - Java Beginners
using 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
methods and access specifiers in java - Java Beginners
methods and access specifiers in java  i am a java beginner..give me the rules f methods and access specifiers  Hi friend, visit for more information: http://www.roseindia.net/java/ http://www.roseindia.net
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
write program - Java Beginners
write 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
code for multiplication of matrix in java using methods
code for multiplication of matrix in java using methods  code for multiplication of matrix in java using methods
WRITE A PROGRAM IN JAVA
WRITE 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 a program in java.
write a program in java.  arrange the natural n umber in 5x5 matrix as 21 22 23 24 25 20 7 8 9 10 19 6 1 2 11 18 5 4 3 12 17 16 15 14 13 i at centerd position and remaining arrange in anticlockwise direction.  
 

 

 

DMCA.com