Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I am currently trying to write a program which reads a text file through a Scanner and on the text file it has peoples names, products they sold and how much they sold products for, and I need the program to read the text file and multiply the numbers together for each person and print the total and I am struggling with how id multiply the numbers together. My current code is
Java
Import java.util.Scanner;
/**
*
* @author Adam
*/
public class PractiseSplit {
    public static void main(String[] args) {
        Scanner Scan = new Scanner (NumberCount.class.getResourceAsStream("pay.txt
        //Scan.useDelimiter(" ^([A-Za-z]+)\\s([0-9]+)\\s([0-9]+)$ ");
        String [] Emma = Scan.split("A-Z
        
        System.out.println("Thes in the String are ");
        while (Scan.hasNext())
        {
            String temp = Scan.next();
            System.out.println(temp);
        }
    
    }
    
}

not sure if im going the best way about it but can anybody give me example code or point out where im going wrong
Thanks
Posted
Updated 2-Jun-15 5:34am
v3
Comments
Richard MacCutchan 2-Jun-15 11:36am    
You need to use the other versions of scan.next, as described in the documentation, to read the data according to its type, e.g scan.nextInt.
Adamdew93 2-Jun-15 11:39am    
so for example because the text file I have is laid out like this
George 12 3
what version would you suggest I use and do you think I will have to split strings to be able to multiply the numbers together

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900