Error of Parsing

Asked

Viewed 121 times

-2

I wrote the code below:

import java.lang.Math;

import.util.Scanner;

public class HelloWorld
{
  public static void main(String[] args)
  {
        int y;
        int cont;
        int i;
        Scanner x = new.Scanner(System.in);
        System.out.print("Digite um número");
        y = x.Scanner();

        for(i = 1 to y) {

            if (y%i == 1){

                cont++;

            } 

            if (y%i == 2){

                cont++;

            }

        }   else{

                System.out.print("O número "+i+" nao e primo");             

                }
    System.out.print(cont)


  }
}

I’m developing an algorithm to count the amount of prime numbers between i and what the user types. Any suggestions for a better algorithm? Gave error of Parsing...

  • What are you trying to do with it here y = x.Scanner();?

  • Misspelled --' kk should be y = x.nextInt();

  • This will not compile, this for is with wrong syntax

  • and how I could fix it?

1 answer

0

for syntax is wrong. You should do:

for(i = 1; i <= y; i++)
  • I think you should take int y and put int x; Scanner read = new Scanner(); x = read.nextInt();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.