Home » Java » Why does not this code run?

Why does not this code run?

Posted by: admin October 26, 2017 Leave a comment

Questions:

In the code you need to take 100 straight-angle triangles and print the biggest triangle. What am I not doing right?

import java.util.Scanner;

public class rthji {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = 0;
        int num1 = 0;
        int num2 = 0;
        int num3 = 0;
        int num4 = 0;
        int num5 = 0;

        System.out.println("Insert the length of the small side of the triangle");
        num = in.nextInt();
        System.out.println("Insert the length of the big of the triangle");
        num1 = in.nextInt();
        System.out.println("Insert the length of the last side of the triangle");
        num2 = in.nextInt();

        for (int i = 1; 1 >= 10; i++) {

            System.out.println("Insert the length of the small side of the triangle");
            num3 = in.nextInt();
            System.out.println("Insert the length of the big of the triangle");
            num4 = in.nextInt();
            System.out.println("Insert the length of the last side of the triangle");
            num5 = in.nextInt();
            if (num3 * num3 + num5 * num5 != num4 * num4) {
                num3 = num4 = num5 = 0;
            } else if (num3 > num && num1 < num4 && num2 < num5) {
                num = num3;
                num1 = num4;
                num2 = num5;
            }
            System.out.println("The ribs of the largest triangle are:" + num1 + (",") + num2 + (",") + num3);
        }
    }
}
Answers:

Your for loop has a error and it should be changed to

  for(int i=1;1<=10;i++)

Questions:
Answers:

Change your for loop like below

for(int i=1; i<=10; i++)