Results 1 to 8 of 8
  1. #1
    stevie171 is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default writing a countdown using java

    hi im writing this as script and i cant think of what i have done wrong can anybody help me?? :)

    import java.util.Scanner;

    public class prod9
    {
    static Scanner sc = new Scanner (System.in);

    public static void main (String[]args)
    {

    System.out.println(" " + " Starting Countdown To Launch ");
    int countdownnumber = 10;
    String input;
    while (true)
    {
    System.out.println(" ");
    if (countdownnumber ==8)



    {
    System.out.println(" Ignition Sequence Start");

    }




    break;

    countdownnumber -=1;
    if (countdownnumber ==0)
    {
    System.out.println(" We have lift off ");
    System.out.println(" ");

    }
    }
    }
    }

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    10

    Default

    Are you receiving errors? If so, what is/are the exact error message(s)? If not, what is the program doing VS what you want it to do?

    (Personally, my guess is because you have a break; statement in there. Try taking that out to see if it helps you at all. But that's just a guess based on the little information you provided.)

  3. #3
    stevie171 is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default

    its just a spaceship count down, from 10 to lift off the error i was getting is

    prod9.java:30: unreachable statement
    countdown number -=1;
    ^
    1error
    i took out the break: statement it compiles but wen i run it im just getting a black screen an keeps jumping to the bottom of the page

    thanks for replyin to me, im not to good at this :)
    Last edited by stevie171; 11-30-2010 at 09:18 PM.

  4. #4
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    10

    Default

    Ah, right.

    You do have to break the function, but only when countdownnumber is equal to zero.

  5. #5
    maknib is offline Member
    Join Date
    Nov 2010
    Posts
    90
    Rep Power
    0

    Default

    Just a Guess

    Java Code:
    import java.util.Scanner;
    
    public class prod9
    {
      static Scanner sc = new Scanner (System.in);
    
      public static void main (String[]args)
      {
    
        System.out.println(" " + " Starting Countdown To Launch ");
        int countdownnumber = 10;
        String input;
        while (true)
        {
          System.out.println(" ");
          if (countdownnumber ==8)
          {
            System.out.println(" Ignition Sequence Start");
          }
          
          [B][SIZE="3"]countdownnumber--;[/SIZE][/B]      
          if (countdownnumber ==0)
          { 
            System.out.println(" We have lift off ");
            System.out.println(" ");
            [B][SIZE="3"]break;[/SIZE][/B]     
          }
        } 
      }
    }
    Wouldn't you want the Sequence to Start at 10 not 8 ?

  6. #6
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    10

    Default

    They don't start the ignition of a rocket shuttle as soon as the countdown begins.

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default

    They don't start the countdown at 10 either ;)

    db

  8. #8
    stevie171 is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default

    on the ball lads, i kinda see wat i did wrong,

    and yes its supposed to start at 10 and instead of 8 its supposed to say ignition sequence start,

    i should really pay more attention in class! :) is their anyway i can get instructions on how to writes these, as i never took dwn my notes in class :)

    Thanks for u replys people

Similar Threads

  1. how to countdown on server side
    By BigBear in forum Java Servlet
    Replies: 3
    Last Post: 04-26-2010, 11:33 PM
  2. countdown timer, little help with method
    By sidy in forum New To Java
    Replies: 22
    Last Post: 07-19-2008, 01:42 PM
  3. Writing a countdown array to a file.
    By kewlgeye in forum New To Java
    Replies: 6
    Last Post: 05-25-2008, 07:09 AM
  4. CountDown timer
    By Seema Sharma in forum AWT / Swing
    Replies: 1
    Last Post: 03-06-2008, 05:26 PM
  5. Please Help - Java Date/Countdown Query
    By desktop_doodle in forum New To Java
    Replies: 2
    Last Post: 01-08-2008, 05:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •