Cycling and bicycle discussion forums. 
   Click here to join our community Log in to access your Control Panel  


Go Back   > >

Foo Off-Topic chit chat with no general subject.

Reply
 
Thread Tools Search this Thread
Old 02-21-11, 03:59 PM   #1
phantomcow2
la vache fantôme
Thread Starter
 
phantomcow2's Avatar
 
Join Date: Aug 2004
Location: NH
Bikes:
Posts: 6,266
Including a "while loop" in my java program.

Can someone tell me what is wrong with my program? I'm trying to set up a while loop so that I read in the number of test cases, then the program asks that many times what the values of x1, x2, y1, and y2 are to compute that distance. For some reason when I run the program it doesn't do anything like it's waiting for an input.



import java.util.Scanner;
import java.text.DecimalFormat;
public class ComputeDistance
{
public static void main (String[] arv)
{
double x1;
double x2;
double y1;
double y2;
double d1;
double distance=0;
int testno;

Scanner scan=new Scanner (System.in);
DecimalFormat answer = new DecimalFormat("0.###");
testno=scan.nextInt();
int count = 1;
while (count <testno)
{
System.out.println("Value of x1?");
x1=scan.nextDouble();
System.out.println("Value of y1?");
y1=scan.nextDouble();
System.out.println("Value of x2?");
x2=scan.nextDouble();
System.out.println("Value of y2?");
y2=scan.nextDouble();
d1=((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2));
distance=Math.sqrt(d1);
count=count++;
System.out.println(answer.format(distance));
**
**
**
__________________
C://dos
C://dos.run
run.dos.run
phantomcow2 is offline   Reply With Quote
Old 02-21-11, 04:03 PM   #2
TexasGuy
That darn Yankee
 
TexasGuy's Avatar
 
Join Date: Jun 2005
Location: West West Fort Worth
Bikes: Mongoose XR-100, Eros Bianchi
Posts: 4,286
lol

that's probably because it's waiting for input.
__________________
Life is about hanging onto what you think is important and finding out what really is important.
"Stop Ruining my joke!", "No, a joke implies humor attached at no additional cost"
So many sayings, so little sig space.
TexasGuy is offline   Reply With Quote
Old 02-21-11, 04:04 PM   #3
RubenX 
Look! My Spine!
 
RubenX's Avatar
 
Join Date: Apr 2008
Location: Kissimmee, FL
Bikes:
Posts: 619
What's the value of testno at the beginning of your program? Print that value out.

I'm also curious about this lines:

System.out.println("Value of x1?");

will it print without a "\n" before waiting for the input?
__________________
"Hoy es un dia normal, pero yo voy a hacerlo intenso" ~ Juanes
RubenX is offline   Reply With Quote
Old 02-21-11, 04:05 PM   #4
TexasGuy
That darn Yankee
 
TexasGuy's Avatar
 
Join Date: Jun 2005
Location: West West Fort Worth
Bikes: Mongoose XR-100, Eros Bianchi
Posts: 4,286
Perhaps putting a
Code:
System.out.println("How many coordinate distances do you wish to find?");
prior to

Code:
testno=scan.nextInt();
will show you where you're at.

Also. You'll probably want to fix
Code:
int count = 1;
while (count <testno)
Think what will happen if the user inputs 1.
__________________
Life is about hanging onto what you think is important and finding out what really is important.
"Stop Ruining my joke!", "No, a joke implies humor attached at no additional cost"
So many sayings, so little sig space.
TexasGuy is offline   Reply With Quote
Old 02-21-11, 04:47 PM   #5
RubenX 
Look! My Spine!
 
RubenX's Avatar
 
Join Date: Apr 2008
Location: Kissimmee, FL
Bikes:
Posts: 619
Don't you love it when we get a chance to talk geeky?

and also... some data validation should be put into play... never trust a user's input, ever.
__________________
"Hoy es un dia normal, pero yo voy a hacerlo intenso" ~ Juanes
RubenX is offline   Reply With Quote
Old 02-21-11, 04:52 PM   #6
TexasGuy
That darn Yankee
 
TexasGuy's Avatar
 
Join Date: Jun 2005
Location: West West Fort Worth
Bikes: Mongoose XR-100, Eros Bianchi
Posts: 4,286
This is obviously a school project. Doing too much will often mean you cheated and will quite often automatically get you an F.
__________________
Life is about hanging onto what you think is important and finding out what really is important.
"Stop Ruining my joke!", "No, a joke implies humor attached at no additional cost"
So many sayings, so little sig space.
TexasGuy is offline   Reply With Quote
Old 02-21-11, 05:00 PM   #7
jsharr
You Know!? For Kids!
 
jsharr's Avatar
 
Join Date: Apr 2005
Location: Just NW of Richardson Bike Mart
Bikes: '05 Trek 1200 / '90 Trek 8000 / '? Falcon Europa
Posts: 6,153
this thread has nothing to do with coffee that I can see!?
__________________
Are you a registered member? Why not? Click here to register. It's free and only takes 27 seconds! Help out the forums, abide by our community guidelines.
Quote:
Originally Posted by colorider View Post
Phobias are for irrational fears. Fear of junk ripping badgers is perfectly rational. Those things are nasty.
jsharr is offline   Reply With Quote
Old 02-21-11, 05:11 PM   #8
phantomcow2
la vache fantôme
Thread Starter
 
phantomcow2's Avatar
 
Join Date: Aug 2004
Location: NH
Bikes:
Posts: 6,266
Quote:
Originally Posted by TexasGuy View Post
This is obviously a school project. Doing too much will often mean you cheated and will quite often automatically get you an F.
Yep. And I'd feel great shame if this was anything other than a practice homework assignment.
__________________
C://dos
C://dos.run
run.dos.run
phantomcow2 is offline   Reply With Quote
Old 02-21-11, 08:36 PM   #9
phantomcow2
la vache fantôme
Thread Starter
 
phantomcow2's Avatar
 
Join Date: Aug 2004
Location: NH
Bikes:
Posts: 6,266
Thanks for the comments . Forgetting the input was pretty dumb; I'm still a noob.
__________________
C://dos
C://dos.run
run.dos.run
phantomcow2 is offline   Reply With Quote
Old 02-21-11, 10:23 PM   #10
jccaclimber
Senior Member
 
Join Date: May 2005
Location: Terre Haute, Lafayette, or Indianapolis, IN, depending on the day
Bikes: n, I would like n+1
Posts: 1,917
Quote:
Originally Posted by RubenX View Post
Don't you love it when we get a chance to talk geeky?

and also... some data validation should be put into play... never trust a user's input, ever.
Attached Images
File Type: png exploits_of_a_mom.png (31.2 KB, 3 views)
jccaclimber is offline   Reply With Quote
Old 02-21-11, 10:53 PM   #11
UmneyDurak
RacingBear
 
UmneyDurak's Avatar
 
Join Date: Dec 2004
Location: NorCal
Bikes:
Posts: 8,519
Quote:
Originally Posted by phantomcow2 View Post
Can someone tell me what is wrong with my program?
You are using JAVA.

Quote:
Originally Posted by jccaclimber View Post
I have that outside my cubicle. Along with this. Not sure how my manager feels about it...
UmneyDurak is offline   Reply With Quote
Old 02-21-11, 10:59 PM   #12
mikeybikes
Senior Member
 
mikeybikes's Avatar
 
Join Date: May 2009
Location: Edgewater, CO
Bikes: Tons
Posts: 3,214
Make sure your program starts with :

while(1) continue;
mikeybikes is offline   Reply With Quote
Old 02-21-11, 11:02 PM   #13
TexasGuy
That darn Yankee
 
TexasGuy's Avatar
 
Join Date: Jun 2005
Location: West West Fort Worth
Bikes: Mongoose XR-100, Eros Bianchi
Posts: 4,286
Quote:
Originally Posted by mikeybikes View Post
Make sure your program starts with :

while(1) continue;
__________________
Life is about hanging onto what you think is important and finding out what really is important.
"Stop Ruining my joke!", "No, a joke implies humor attached at no additional cost"
So many sayings, so little sig space.
TexasGuy is offline   Reply With Quote
Old 02-21-11, 11:03 PM   #14
TexasGuy
That darn Yankee
 
TexasGuy's Avatar
 
Join Date: Jun 2005
Location: West West Fort Worth
Bikes: Mongoose XR-100, Eros Bianchi
Posts: 4,286
Quote:
Originally Posted by UmneyDurak View Post
You are using JAVA.



I have that outside my cubicle. Along with this. Not sure how my manager feels about it...
__________________
Life is about hanging onto what you think is important and finding out what really is important.
"Stop Ruining my joke!", "No, a joke implies humor attached at no additional cost"
So many sayings, so little sig space.
TexasGuy is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT -6. The time now is 06:19 PM.