• Java code to display a message after a specific days

    SapnaVishwas Member

    I have a problem regarding java code
    i want a code that display a message after a specific days
    my idea is to use

    int day;
    final day = 31;
    if (days <=31)
    System.out.println ("Please restock");

    that the idea…
    somehow it seems illogical….
    anyone can help please help…..

  • Adan Member

    It is really a bad programming, but if you are a beginner you are allowed to do this mistake a couple of times!

    Generally you could return more than one object in a java method by using an array. For example the following method returns an Object array:

    Object[] testMethod() {
    Object a,b;
    ........
    ........
    Object[] obj = new Object[2];
    obj[0]=a;
    obj[1]=b;
    return obj;
    }
    

    You can access the returned value by:

    Object[] ret = testMethod();
    System.out.println(ret[0]);
    System.out.println(ret[1]);
    
  • Ganesh Member

    Here is my timer example, enjoy:

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.Timer;
    public class TimerTest {
    public static void main(String[] args) {
    Timer timer = new Timer(1000, new Listener()); //creates a timer
    //that ticks once every
    //second and creates a new
    //ActionListener timer.start(); //starts the timer while(true);
    //Infinite loop that insures the program won't end
    //if it wasn't here the program would end before the
    //timer has a chance to start. } }
    class Listener implements ActionListener {
    private int minutes = 0;
    private int hours = 0;
    private int secs = 0;
    
    @Override public void actionPerformed(ActionEvent e) {
    secs++; if(secs == 60)
    { secs = 0; minutes++; if(minutes == 60) { minutes = 0; hours++; } }
    
    System.out.println(hours + " : " + minutes + " : " + secs); } }
    
Viewing 2 reply threads
  • You must be logged in to reply to this topic.