Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8036609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:40:22+00:00 2026-06-05T02:40:22+00:00

This is my program it reads from a file but I was away for

  • 0

This is my program it reads from a file but I was away for the lecture for file readers so I’m winging it.
This program currently reads in one line and prints out the top 3 values from it but it only works with one line in the file.

import java.util.*;
import java.io.*;
public class ProcessdatdereFile
{
    public static void main (String[] args)throws IOException{
        List namenum=readM("data/raw.txt");
        dataProcess(namenum);
    }

    public static List readM(String filename)throws IOException{
        Scanner fr=new Scanner(new FileReader(filename));
        List<String>namenum=new ArrayList<String>();
        while(fr.hasNext()){
            namenum.add(fr.next());
        }
        fr.close();
        Collections.sort(namenum,Collections.reverseOrder());
        return namenum;
    }

    public static void dataProcess(List namenum)throws IOException{
        for(int i=0;i<4;i++){
            System.out.printf("%s ",namenum.get(i));
        }
        System.out.println("");
    }
}

raw.txt contains

Mary 45 87 23 76
Joe 34 76 12 78 34 87
Anne 90 5 99

The program needs to print each name and the top 3 scores on individual lines.
Lengthy replies are welcome.
Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:40:23+00:00Added an answer on June 5, 2026 at 2:40 am
    public static void main (String[] args)throws IOException{
        String filename = "data/raw.txt";
        Scanner fr=new Scanner(new FileReader(filename));
        //reads the line and passes it to another method where it is put into a list
        String line;
        while(fr.hasNextLine()){
            line=fr.nextLine();
            List namenum=readM(line);
            dataProcess(namenum);
        }
        fr.close();        
    }
    
    public static List readM(String line)throws IOException{
        Scanner scn=new Scanner(line);
        List<String>namenum=new ArrayList<String>();
        while(scn.hasNext()){
            namenum.add(scn.next());
        }
        Collections.sort(namenum,Collections.reverseOrder());
        return namenum;
    }
    

    Ive changed these two methods so that it processes them as a line each rather than each string in the file. It now takes each Line and prints it out with the name and 3 top scores.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently my program reads images and text in a record from an xml file,
This is a clojure program to read integers from a file and count the
Below is the program that I wrote. /******************************************************************************* * This program reads EOF from
This program reads emails (really just a .txt file structured like an email) and
I'm trying to create a program that reads this text file with a list
this is a small program using Java Scanner which reads a file of double
We have an asp.net c# program that reads a sheet from an Excel file
I have got this read file code from microsoft @C:\Users\computing\Documents\mikec\assignment2\task_2.txt That works fine when
For my program I want to read a key from a properties file and
I'm trying to do this: cmd.exe /C C:\Program Files\Somewhere\SomeProgram.exe > C:\temp\Folder Containing Spaces\SomeProgram.out However,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.