0

I'm a beginner in java. I'm trying to debug a simple program that returns the number of digits of an entered number. After inserting the breakpoint and starting debugging it says "No variable to display because there is no current thread"

package learning1;

import java.util.Scanner;
import java.lang.Math;
public class Learning1 {

 public static void main(String[] args) { 
     int a;
     Scanner scan = new Scanner (System.in);
     System.out.print("Enter number");
     a = scan.nextInt();
     int i=a;
     int count=0;
     while(i>1){
         i = a%10;
         count = count + 1;
     }
     System.out.print("Number of digits is " + count );
   }

}

Hamzzz
  • 3
  • 1
  • 5

1 Answers1

0

Well, it depends where you place your breakpoint. Take your mouse pointer and click on the editor line number where the line:

public static void main(String[] args) { 

enter image description here

is located. A light red triangle should appear over the line number:

enter image description here

or you can set a break-point on a line within the main() method. For example, if you click on the editor line number 12 you will see a light red square and the entire code line itself is highlighted with the same color:

enter image description here

Now all you need to do is select the Debug Project toolbar button or select Debug Project from the Debug menu bar to run your application in Debug mode:

enter image description here

When your code runs and it reaches the break point the red highlighted line will turn green and you can view your variables as then become declared and initialized within the Variables tab of the pane below the editor:

enter image description here

To step through your code one line at a time just hit the F8 key on your keyboard.

DevilsHnd - 退職した
  • 8,739
  • 2
  • 19
  • 22