• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem with scanner  RSS feed

 
jonathan roach
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am trying to create a program that prompts the user to give the name of a file, which it then reads and does simple calculations. i dont know how to use the user input to read in teh file. can anyone help me?


this is what i have:

import java.util.*;
import java.io.*;

public class GradesFromFile {

/**
* @uthor: Jonathan Roach
*/
public static void main(String[] args)throws IOException
{
// TODO Auto-generated method stub

System.out.print("input the name of the file that you wish to read:");
Scanner in = new Scanner(System.in);


double score = 0;
double numberOfScores = 0;
double highScore = 0;
double lowScore = 100;
double sumOfScores = 0;
double numberAs=0;
double numberBs=0;
double numberCs=0;
double numberDs=0;
double numberFs=0;
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jonathan,
Welcome to JavaRanch!

If you look at the JavaDoc for java.util.Scanner, you will see a next method that gives you the data the user entered. The next step is to open a file and read it using that string.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!