``````import java.util.Scanner;

public class Exercise3_1 {
public static void main (String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter three edges: ");
int integer = input.nextInt();
int edge1 = 1;
int edge2 = 1;
int edge3 = 1;
// First condition: edge1 + edge2 should be greater than or equal to edge3
boolean triangle = (edge1 + edge2 >= edge3);
// Second condition: edge1 + edge3 should be greater than edge2
triangle =!(triangle && (edge1 + edge3 > edge2));
// Third condition: edge2 + edge3 should be greater than edge1
triangle =!(triangle && (edge2 + edge3 > edge1));
System.out.println("Can edges " + edge1 + ", " + edge2 + "," + " " + "and "  +   edge3 + " form a triangle? " + triangle);
}
}
``````

## Recommended Answers

Please explain what the problem is.
Show the program's output and explain what is wrong with it and show what you want the output to be.

Can you show Exactly what the program outputs
and then show exactly what you want the output to be
instead of writing it as a paragraph with wrapping lines etc?

Here is what I get when I execute the code:

Enter three edges: 111
Can edges 1, 1, and 1 form a triangle? true

## All 11 Replies

Please explain what the problem is.
Show the program's output and explain what is wrong with it and show what you want the output to be.

Well, when I submit the assingment, the correct output should generates : Enter three edges: Can edges 5, 1, and 1 form a triangle? false... while mine generates: Enter three edges: Can edges 1, 1, and 1 form a triangle? true... then in the second round the correct output should be- Enter three edges: Can edges 2, 2, and 3 form a triangle? true.. and mine generates Can edges 1, 1, and 1 form a triangle? true

Can you show Exactly what the program outputs
and then show exactly what you want the output to be
instead of writing it as a paragraph with wrapping lines etc?

Here is what I get when I execute the code:

Enter three edges: 111
Can edges 1, 1, and 1 form a triangle? true

My output is: Enter three edges: Can edges 1, 1, and 1 form a triangle? tru

the output should be: Enter three edges: Can edges 2, 2, and 3 form a triangle? tru

My output is: Enter three edges: Can edges 1, 1, and 1 form a triangle? tru

the out put should be: Enter three edges: Can edges 5, 1, and 1 form a triangle? false

yes and when I submit the assignment... the code satisfies one of the three outputs... my program is not generating the first two outputs i listed above

Your code assigns the value of 1 to the three variables that are used in the logic.
If you want different values to be used and printed out you need to change the values that are assigned to those variables. For example:

``````int edge1 = 2;
int edge2 = 2;
int edge3 = 3;``````

Your copy of the console does NOT show what you entered. Why is that?
Look at my post, it shows that I entered 111

when I submit the assignment this is what I get:

 => copied your uploaded file to /home/bmexia0/Exercise3_1.java
 => Testing File: /home/bmexia0/Exercise3_1.java
 => /home/bmexia0
 => Compiling /home/bmexia0/Exercise3_1.java...
 => Compiled Okay
 => Testing Exercise3_1.java Round 0 : its not okay!
 => diff side by side difference, common lines suppressed showing first 130 Characters
 => Your incorrect output left side, solution right hand side.
 => Enter three edges: Can edges 2, 2, and 3 form a triangle? tru | Enter three edges: Can edges 1, 1, and 1 form a triangle? tru
 => Character Dump Your Output...
 => 0000000 E n t e r t h r e e e d g e
 => 0000020 s : C a n e d g e s 2 ,
 => 0000040 2 , a n d 3 f o r m a
 => 0000060 t r i a n g l e ? t r u e \n
 => 0000077
 => Character Dump Solution...
 => 0000000 E n t e r t h r e e e d g e
 => 0000020 s : C a n e d g e s 1 ,
 => 0000040 1 , a n d 1 f o r m a
 => 0000060 t r i a n g l e ? t r u e \n
 => 0000077
 => Testing Exercise3_1.java Round 1 : its aokay
 => Testing Exercise3_1.java Round 2 : its not okay!
 => diff side by side difference, common lines suppressed showing first 130 Characters
 => Your incorrect output left side, solution right hand side.
 => Enter three edges: Can edges 2, 2, and 3 form a triangle? tru | Enter three edges: Can edges 5, 1, and 1 form a triangle? fal
 => Character Dump Your Output...
 => 0000000 E n t e r t h r e e e d g e
 => 0000020 s : C a n e d g e s 2 ,
 => 0000040 2 , a n d 3 f o r m a
 => 0000060 t r i a n g l e ? t r u e \n
 => 0000077
 => Character Dump Solution...
 => 0000000 E n t e r t h r e e e d g e
 => 0000020 s : C a n e d g e s 5 ,
 => 0000040 1 , a n d 1 f o r m a
 => 0000060 t r i a n g l e ? f a l s e \n
 => 0000100
 => 1 out of 3 Percentage 33.00

Sorry im so new to this

Sorry, I'm not familiar with how you are having your program executed.
I execute my programs with the java command in a command prompt console.

The way you have your program written, you have to edit it to change the numbers being used for the testing.
The program prints a message and reads an integer from the user but then does not do anything with that number.

What is the program supposed to do when it executes? Explain what the user will see and what the user is supposed to do when the program is executed.

this is the correct program... i got it:) thank you!

``````import java.util.Scanner;

public class Exercise3_1 {
public static void main (String[] args) {
// Input
Scanner input = new Scanner(System.in);
System.out.print("Enter three edges: ");
int edge1 = input.nextInt();

int edge2 = input.nextInt();

int edge3 = input.nextInt();

//Process

// First condition: edge1 + edge2 should be greater than or equal to edge3
boolean triangle = (edge1 + edge2 >= edge3);
// Second condition: edge1 + edge3 should be greater than edge2
triangle =(triangle && (edge1 + edge3 > edge2));
// Third condition: edge2 + edge3 should be greater than edge1
triangle =(triangle && (edge2 + edge3 > edge1));

//Output

System.out.println("Can edges " + edge1 + ", " + edge2 + "," + " " + "and " + edge3 + " form a triangle? " + triangle);

}
}
``````

Now you are getting the three numbers from the user.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.