Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
ඔයාගෙ Assignment හෝ Thesis එක හරියට හදාගමු
ErMurazor
Updated:
Yesterday at 10:52 PM
Ad icon
BlackWall V2ray servers
hu KANNA
Updated:
Wednesday at 4:58 AM
Peppa Pig Family Plush Toy Set – 5 Characters
anil1961
Updated:
Sep 19, 2026
Ad icon
Express VPN PC - 1 Year Rs. 600.00
Sanathbh
Updated:
Sep 19, 2026
Ad icon
Capcut Pro 7 Days Team Plan - Rs. 3️⃣0️⃣0️⃣
Sanathbh
Updated:
Sep 19, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Talk!
Simple java Programme
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="rclakmal" data-source="post: 5590018" data-attributes="member: 98858"><p>Hey Guys check out this code !!!! get two points and return the line !! checked for all occurrences !!!! Please tell me if there are any errors !!!!!!</p><p></p><p>[code]</p><p>package line;</p><p>import java.util.Scanner;</p><p></p><p>/**</p><p> *</p><p> * @author lakmal</p><p> */</p><p> class Line {</p><p> Points p1=new Points();</p><p> Points p2=new Points();</p><p> static boolean isContinue=true;</p><p> static Scanner input=new Scanner(System.in);</p><p> static String op;</p><p></p><p> </p><p></p><p> void getLine(Points p1,Points p2){</p><p> System.out.println("Your two points are ");</p><p> System.out.println("("+p1.xCordinate+","+p1.yCordinate+")");</p><p> System.out.println("("+p2.xCordinate+","+p2.yCordinate+")");</p><p> double yCoeff=p2.xCordinate-p1.xCordinate;</p><p> double xCoeff=p2.yCordinate-p1.yCordinate;</p><p> double constant=p1.yCordinate*(p2.xCordinate-p1.xCordinate)-p1.xCordinate*(p2.yCordinate-p1.yCordinate);</p><p> System.out.println("Your Line is:");</p><p> if (yCoeff==0){</p><p> System.out.println("X="+p2.xCordinate);</p><p> }</p><p> else if (xCoeff==0)</p><p> System.out.println("Y="+p2.yCordinate);</p><p> else{</p><p> if (constant!=0){</p><p> if ((constant/yCoeff)>0){</p><p> op = "+";</p><p> }</p><p> else if ((constant/yCoeff)<0){</p><p> op="";</p><p> }</p><p></p><p> System.out.println("Y="+xCoeff/yCoeff+"X" + op + (constant)/yCoeff);</p><p> }</p><p> else</p><p> System.out.println("Y="+ xCoeff/yCoeff+"X");</p><p> }</p><p> }</p><p></p><p></p><p> void getPoints(){</p><p> System.out.println("Enter your First Point:");</p><p> System.out.print("X=");</p><p></p><p> this.p1.xCordinate=input.nextInt();</p><p> System.out.print("Y=");</p><p> this.p1.yCordinate=input.nextInt();</p><p></p><p> System.out.println("Enter your Second Point:");</p><p> System.out.print("X=");</p><p> this.p2.xCordinate=input.nextInt();</p><p> System.out.print("Y=");</p><p> this.p2.yCordinate=input.nextInt();</p><p> this.getLine(this.p1,this.p2);</p><p> }</p><p></p><p></p><p> public static void main(String[] args) {</p><p> do {</p><p></p><p> Line l1=new Line();</p><p> l1.getPoints();</p><p> </p><p> System.out.println("Do you want to Continuw with anothe line:(y/n)");</p><p> char state=input.next().charAt(0);</p><p> if (state=='n')</p><p> isContinue=false;</p><p></p><p> } while (isContinue=true);</p><p></p><p> }</p><p>}</p><p></p><p>class Points {</p><p> int xCordinate;</p><p> int yCordinate;</p><p></p><p>}</p><p>[/code]</p><p></p><p>Happy Codings !!!!! For More Java And C++ codes Visit </p><p></p><p><span style="font-family: 'Comic Sans MS'"><span style="font-size: 18px"><span style="color: Black"><strong><a href="http://www.elakiri.com/forum/showthread.php?t=245895" target="_blank">http://www.elakiri.com/forum/showthread.php?t=245895</a></strong></span></span></span></p></blockquote><p></p>
[QUOTE="rclakmal, post: 5590018, member: 98858"] Hey Guys check out this code !!!! get two points and return the line !! checked for all occurrences !!!! Please tell me if there are any errors !!!!!! [code] package line; import java.util.Scanner; /** * * @author lakmal */ class Line { Points p1=new Points(); Points p2=new Points(); static boolean isContinue=true; static Scanner input=new Scanner(System.in); static String op; void getLine(Points p1,Points p2){ System.out.println("Your two points are "); System.out.println("("+p1.xCordinate+","+p1.yCordinate+")"); System.out.println("("+p2.xCordinate+","+p2.yCordinate+")"); double yCoeff=p2.xCordinate-p1.xCordinate; double xCoeff=p2.yCordinate-p1.yCordinate; double constant=p1.yCordinate*(p2.xCordinate-p1.xCordinate)-p1.xCordinate*(p2.yCordinate-p1.yCordinate); System.out.println("Your Line is:"); if (yCoeff==0){ System.out.println("X="+p2.xCordinate); } else if (xCoeff==0) System.out.println("Y="+p2.yCordinate); else{ if (constant!=0){ if ((constant/yCoeff)>0){ op = "+"; } else if ((constant/yCoeff)<0){ op=""; } System.out.println("Y="+xCoeff/yCoeff+"X" + op + (constant)/yCoeff); } else System.out.println("Y="+ xCoeff/yCoeff+"X"); } } void getPoints(){ System.out.println("Enter your First Point:"); System.out.print("X="); this.p1.xCordinate=input.nextInt(); System.out.print("Y="); this.p1.yCordinate=input.nextInt(); System.out.println("Enter your Second Point:"); System.out.print("X="); this.p2.xCordinate=input.nextInt(); System.out.print("Y="); this.p2.yCordinate=input.nextInt(); this.getLine(this.p1,this.p2); } public static void main(String[] args) { do { Line l1=new Line(); l1.getPoints(); System.out.println("Do you want to Continuw with anothe line:(y/n)"); char state=input.next().charAt(0); if (state=='n') isContinue=false; } while (isContinue=true); } } class Points { int xCordinate; int yCordinate; } [/code] Happy Codings !!!!! For More Java And C++ codes Visit [FONT=Comic Sans MS][SIZE=5][COLOR=Black][B][url]http://www.elakiri.com/forum/showthread.php?t=245895[/url][/B][/COLOR][/SIZE][/FONT] [/QUOTE]
Insert quotes…
Verification
Hathara warak wissa keeyada? (Hathara wadi karanna 20)
Post reply
Top
Bottom