0

Hi guys

I am trying to build a program which scans data from a text file, but I keep getting an error when trying to compile it.

The code

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Scanner;
import java.io.*;

class anything extends JFrame
{
	public anything()
	{
		File stuff = new File(stuff.txt);
		Scanner scan = Scanner(stuff);
		int length; 
		int count = 0;
		double place;
			
			while(scan.hasNextDouble())
			{
				place = scan.NextDouble();
					count++;
			}

This isn't the whole program, but is the part which has Scanner.

The errors

cannot find symbol variable txt
cannot find symbol method Scanner(java.io.File)
cannot find symbol method NextDouble()

So what is the problem, I have a feeling it has to do with the importing of scanner or something.

3
Contributors
3
Replies
9
Views
8 Years
Discussion Span
Last Post by javalearn
0

This: File stuff = new File(stuff.txt); Should be: File stuff = new File([B]"[/B]stuff.txt[B]"[/B]); This: Scanner scan = Scanner(stuff); Should be: Scanner scan = [B]new[/B] Scanner(stuff); This: place = scan.NextDouble(); I think should be: place = scan.[B]n[/B]extDouble(); Look at this: Scanner

0

Thanks very much man, I never would have found such an annoying error.

Thanks!

-1
import java.util.Scanner;
class Handling
{
    public static int quotient(int a,int b)
    {

        return(a/b);

    }
public static void main(String[] arg)
{
    Scanner scanner=new Scanner(System.in);

    System.out.println(" enter value of a");

    int a=scanner.nextInt();

    System.out.println(" enter value of b");

    int b=scanner.nextInt();

    int result=quotient(a,b);

    System.out.println("\n result: a / b =  " +result);

    try 
    {
        result=quotient(a,b);
    }
    catch(Exception e)
    {
        System.out.println(" this is catch");
    }
    finally
    {
        System.out.println(" this is finally");
    }
}

Edited by Reverend Jim: Fixed formatting

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.