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
එක පැකේජ් එකයි මාසෙටම Unlimited Internet. තාමත් DATA CARD දාන්න සල්ලි වියදම් කරනවද? අඩුම මිලට අපෙන්.
sayuru bandara
Updated:
Tuesday at 12:30 PM
Ad icon
ඉන්ටර්නෙට් එකෙන් හරියටම සල්ලි හොයන්න සහ Success වෙන්න කැමතිද? 🚀 (E-Money & Success Stories)
siri sumana
Updated:
Saturday at 11:44 PM
Gemini AI PRO 18 months Offer
Hawaka
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 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: 5590029" 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 !!!!!!It will be a great Help !!! And Visit<a href="http://www.elakiri.com/forum/showthread.php?t=245895" target="_blank"> <strong><span style="font-family: 'Comic Sans MS'"><span style="font-size: 18px"><span style="color: Black"><strong>http://www.elakiri.com/forum/showthread.php?t=245895 for more problems !!!!!!</strong></span></span></span></strong></a></p><p><a href="http://www.elakiri.com/forum/showthread.php?t=245895" target="_blank"></a> </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><a href="http://www.elakiri.com/forum/showthread.php?t=245895" target="_blank"><span style="font-family: 'Comic Sans MS'"><span style="font-size: 18px"><span style="color: Black"><strong>http://www.elakiri.com/forum/showthread.php?t=245895</strong></span></span></span></a></p></blockquote><p></p>
[QUOTE="rclakmal, post: 5590029, 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 !!!!!!It will be a great Help !!! And Visit[URL="http://www.elakiri.com/forum/showthread.php?t=245895"] [B][FONT=Comic Sans MS][SIZE=5][COLOR=Black][B]http://www.elakiri.com/forum/showthread.php?t=245895 for more problems !!!!!![/B][/COLOR][/SIZE][/FONT][/B] [/URL] [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 [URL="http://www.elakiri.com/forum/showthread.php?t=245895"][FONT=Comic Sans MS][SIZE=5][COLOR=Black][B]http://www.elakiri.com/forum/showthread.php?t=245895[/B][/COLOR][/SIZE][/FONT][/URL] [/QUOTE]
Insert quotes…
Verification
Nawa warak dahaya keeyada? (Namaya wadi kireema dahaya)
Post reply
Top
Bottom