Syntax error on token . Identifier expected after this token in Java


In this program i am going to read 1 to n numbers in Java.

Error Message: Unresolved compilation problem:
       Syntax error on token ".", Identifier expected after this token
Error Description:
Scanner Syntax is wrong we Should not place (.)
      
package com.lib;

import java.util.Scanner;

public class Print1toN
{
       public static void main(String[] args)
       {
      
              Scanner num = new Scanner.(System.in);
              System.out.println("enter n value:");
              int n = num.nextInt();
              for(double a=1.0;a<=n;a++)
              {
                     System.out.println(a);
              }num.close();
       }
}


Error Solution:
In the below program we removed (.)
package com.lib;

import java.util.Scanner;

public class Print1toN
{
       public static void main(String[] args)
       {
      
              Scanner num = new Scanner(System.in);
              System.out.println("enter n value:");
              int n = num.nextInt();
              for(double a=1.0;a<=n;a++)
              {
                     System.out.println(a);
              }num.close();
       }
}

Output: enter n value:
3
1.0
2.0
3.0
Share this post :

Post a comment

Please share your valuable feedback and share this article in social media.

 
Support : Ranga Rajesh Kumar
Copyright © 2019. Error Solution - All Rights Reserved
Site Designed by Ranga Rajesh Kumar