## 11646 - Athletics Track

Moderator: Board moderators

mklovemu
New poster
Posts: 1
Joined: Fri Sep 04, 2009 9:11 am

### 11646 - Athletics Track

Hi all,
I have tried to solve this problem but I got a runtime error. I found out that my program have not terminated, so can anybody how to built a loop input from keyboard tills stop typing anymore?
Here's my code:
import java.util.*;

public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
while(sc.hasNext()){
StringTokenizer temp=new StringTokenizer(s,":");
int length=Integer.parseInt(temp.nextToken());
int width=Integer.parseInt(temp.nextToken());
double tan=(double)(width)/(double)(length);
double angle=Math.atan(tan);
if(angle<0) angle=Math.PI+angle;
angle*=2;
double r=Math.sqrt((double)(width*width+length*length))/2;
double perimeter=r*angle*2+(double)length*2;
double l=(double)(length*400)/perimeter;
double w=(double)(width*400)/perimeter;
System.out.printf("%.10f %.10f\n",l,w);
s=sc.nextLine();
}
}

}

the sc.hasNect() always true, so how can I fix it?

arifcsecu
Learning poster
Posts: 64
Joined: Fri Sep 25, 2009 11:29 am
Location: Chittagong,University of chittagong
Contact:

### Re: 11646 Atheletics Track

i solved it in C++

input :

int main()
{
flaoat a,b;
char ch;

while(scanf("%lf %s %lf",&a,ch,&b)==3)
{

process

output

return 0;
}
Try to catch fish rather than asking for some fishes.

plamplam
Experienced poster
Posts: 150
Joined: Fri May 06, 2011 11:37 am

### Re: 11646 Atheletics Track

I solved it in C. Input is terminated in this problem by eof.

for (; ;)
{
gets(str);
if (feof(stdin)) break;
}
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson