Mind helping a newcomer who hit their first speed bump?
<p>I just started learning how to program in Java. Everything was going well so far.. That was until I came across this "bonus" question/problem our teacher gave us to solve as an additional "challenge".</p>

<p><a href="https://i.stack.imgur.com/mr8Qp.png" rel="nofollow noreferrer">Please click here to view the Question and the Sample input/output</a> (it's an image file)</p>

<p>Note that I'm not allowed to use anything that wasn't taught or discussed in class. So, things like arrays, method overloading, parsing arrays to methods, parseInt, etc. gets ruled out.</p>

<p>Here's what I was able to come up with, so far:</p>

<pre><code>import java.util.Scanner;
public class Test 
{
    public static void main(String[] args) 
    {
         int N; // number of lines of input
         double length1, length2, length3; // the 3 lengths
         double perimeter; // you get this by adding the 3 lengths
         double minperimeter=0; // dummy value

         Scanner input = new Scanner(System.in);
         System.out.println("Enter the number of triangles you have:");
         N = input.nextInt();

         System.out.println("Insert the lengths of the sides of these " +  
                            "triangles (3 real numbers per line):");

         for (int counter=0; counter&lt;N; counter++)
         {
             length1 = input.nextDouble();
             length2 = input.nextDouble();
             length3 = input.nextDouble();

             perimeter = (length1 + length2 + length3);
             minperimeter = Math.min(perimeter,Math.min(perimeter,perimeter));
         }

         System.out.printf("The minimum perimeter is %.1f%n", minperimeter); 
    }
}
</code></pre>

<p><em>My 2 main problems are</em>:</p>

<p><s>1) The program only stores and works with the 'last' input.
The ones before it get <strong>replaced</strong> with this one.</s> [update: solved this problem]</p>

<p><s>2) How do I <strong>print the "triangle number"</strong> in the final output?</s> [update: solved this problem, too]</p>

<p><s>So, can anyone please help me come up with a solution that requires only the very basic learnings of Java?</s> If it helps, <a href="http://catalogue.pearsoned.co.uk/educator/product/Java-How-to-Program-Late-Objects-Global-Edition/9781292019369.page" rel="nofollow noreferrer">this is the book</a> we're using. Currently at Chapter 4. But we did learn about Math Class (which is in Chapter 5).</p>

<p><strong>Update</strong>: Thank you so much for your replies, everyone! I was able to come up with a solution that does exactly what was asked in my question.</p>