[Java] Unable to reach symbol in the line 19

hello, i have an error in the line 19 of the code. Can somebody help me?

package com.company;

import javax.swing.*;

public class Main {
    public static void main(String[] args) {
        double max = Double.MIN_VALUE;
        double min = Double.MAX_VALUE;

        while (true) {
            String sa = JOptionPane.showInputDialog("tal: ");
            if (sa == null)
            double tal = Double.parseDouble(sa);
            double maxfinal = Math.max(max, tal);
            double minfinal = Math.min(min, tal);

           JOptionPane.showMessageDialog(null, "storsta  " + minfinal + " misnta:" + maxfinal);


I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.


I am adding “Java” to your title, so that people can see what languege this is about before opening the thread.
If it is the wrong language, please edit your title.


The reason you are getting an error on line 19 is because you are trying to access variable minfinal and maxfinal outside their scope. The visibility of these variables are limited to the while loop block.