-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsortest_path.java
More file actions
35 lines (30 loc) · 849 Bytes
/
sortest_path.java
File metadata and controls
35 lines (30 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.*;
public class sortest_path {
public static void sortest_distance(String s){
int x=0,y=0;
for(int i=0;i<s.length();i++){
if(s.charAt(i)=='n'){
y++;
}
if(s.charAt(i)=='s'){
y--;
}
if(s.charAt(i)=='e'){
x++;
}
if(s.charAt(i)=='w'){
x--;
}
}
float path=(float)Math.sqrt(x*x+y*y);
System.out.println(x);
System.out.println(y);
System.out.print("sortest path is : "+path);
}
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println("enter the path in the form of e,w,n,s : ");
String s=sc.next();
sortest_distance(s);
}
}