Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Or triangle exist

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Location
    Lithuania
    Posts
    23
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Or triangle exist

    Hello guys, so i want create little program which enter the number, ant program says triangle exist or not. So code :
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
    import javax.swing.*;
     
    public class Panel extends JFrame implements ActionListener {
     
    	JTextField one;
    	JTextField two;
    	JTextField three;
    	JButton check;
    	JPanel panele;
    	JLabel answer;
     
    	int a,b,c;
    	public Panel() {
     
    		panele = new JPanel();
    		panele.setSize(500,500);
    		panele.setLayout(null);
     
    		one = new JTextField();
    		one.setSize(120,30);
    		one.setLocation(20,30);
    		one.setFont(new Font("Arial",Font.BOLD,24));
     
    		two = new JTextField();
    		two.setSize(120,30);
    		two.setLocation(20,65);
    		two.setFont(new Font("Arial",Font.BOLD,24));
     
    		three = new JTextField();
    		three.setSize(120,30);
    		three.setLocation(20,100);
    		three.setFont(new Font("Arial",Font.BOLD,24));
     
    		check = new JButton("Check");
    		check.setSize(70,70);
    		check.setLocation(170,30);
     
     
    		add(panele);
     
    		panele.add(one);
    		panele.add(two);
    		panele.add(three);
    		panele.add(check);
     
    		check.addActionListener(this);
     
    	}
     
    	public void actionPerformed(ActionEvent e) {
    		try {
     
     
    		a = (int) Integer.parseInt(one.getText());
    		b = (int) Integer.parseInt(two.getText());
    		c = (int) Integer.parseInt(three.getText());
     
     
     
    		}catch(Exception e1) {
    		JOptionPane.showMessageDialog(null,"Only Numbers","Klaida",JOptionPane.ERROR_MESSAGE);
     
    		}
     
    		/*
    		 * Or triangle exist?? Formul :
    		 * a+b > c
    		 * a+c > b
    		 * c+b > a
    		 * 
     
    		 */
     
    		if (a+b > c || a+c > b || c+b > a) {
    			JOptionPane.showMessageDialog(null,"Exist","Atsakymas",JOptionPane.INFORMATION_MESSAGE);
    		}  else {
    			JOptionPane.showMessageDialog(null,"Not exist","Atsakymas",JOptionPane.INFORMATION_MESSAGE);
    		}
     
     
    	}
     
     
     
    }

    So when i put first num like 1, next num like 2 and next num like 100 , program says Triangle exist. How fix it? Can you help me? Thanks


  2. #2
    Member
    Join Date
    Feb 2014
    Posts
    180
    Thanks
    0
    Thanked 48 Times in 45 Posts

    Default Re: Or triangle exist

    The triangle inequality theorem states that "for any triangle, the sum of the lengths of any two sides must be greater than the length of the remaining side." (Triangle inequality - Wikipedia, the free encyclopedia) This should translate to an AND (&&) relationship between each of the expressions, not OR (||).

  3. The Following User Says Thank You to jashburn For This Useful Post:

    xkendzu (March 16th, 2014)

  4. #3
    Junior Member
    Join Date
    Jan 2014
    Location
    Lithuania
    Posts
    23
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Or triangle exist

    You say, i must changed || to && ?

    --- Update ---

    Thanks It help

Similar Threads

  1. Package x does not exist????
    By big10p in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 23rd, 2013, 05:11 AM
  2. Package does not exist
    By AceX in forum Java Theory & Questions
    Replies: 5
    Last Post: February 22nd, 2013, 03:11 PM
  3. No such file or directory exist (help!)
    By hawkeye10 in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: October 14th, 2012, 09:36 PM
  4. PROBLEM CHECKING IF RECORDS EXIST OR DO NOT EXIST IN DATABASE
    By jimmyb0206 in forum JDBC & Databases
    Replies: 1
    Last Post: April 10th, 2011, 09:18 AM
  5. org.apache.derby does not exist?
    By disclaimer in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 30th, 2010, 04:58 PM