Results 1 to 8 of 8
Thread: writing a countdown using java
- 11-30-2010, 07:38 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
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(" ");
}
}
}
}
- 11-30-2010, 07:58 PM #2
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.)
- 11-30-2010, 08:13 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
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 08:18 PM.
- 12-01-2010, 12:32 AM #4
Ah, right.
You do have to break the function, but only when countdownnumber is equal to zero.
- 12-01-2010, 02:07 AM #5
Member
- Join Date
- Nov 2010
- Posts
- 90
- Rep Power
- 0
Just a Guess
Wouldn't you want the Sequence to Start at 10 not 8 ?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] } } } }
- 12-01-2010, 04:10 AM #6
They don't start the ignition of a rocket shuttle as soon as the countdown begins.
- 12-01-2010, 04:56 AM #7
They don't start the countdown at 10 either ;)
db
- 12-01-2010, 04:52 PM #8
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
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
-
how to countdown on server side
By BigBear in forum Java ServletReplies: 3Last Post: 04-26-2010, 10:33 PM -
countdown timer, little help with method
By sidy in forum New To JavaReplies: 22Last Post: 07-19-2008, 12:42 PM -
Writing a countdown array to a file.
By kewlgeye in forum New To JavaReplies: 6Last Post: 05-25-2008, 06:09 AM -
CountDown timer
By Seema Sharma in forum AWT / SwingReplies: 1Last Post: 03-06-2008, 04:26 PM -
Please Help - Java Date/Countdown Query
By desktop_doodle in forum New To JavaReplies: 2Last Post: 01-08-2008, 04:53 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks