Answered You can hire a professional tutor to get the answer.

QUESTION

I need to count words and line and character from input text file however, I just dont know how to count the single characeter without white space.

I need to count words and line and character from input text file however, I just dont know how to count the single characeter without white space.Can you please help me?=======================================================import java.io.*;import java.util.*;public class Chapter6{public static void main(String[] args)throws FileNotFoundException{ Scanner console=new Scanner(System.in); System.out.println("What is the file name? "); String name=console.nextLine(); Scanner input=new Scanner(new File(name)); String s=input.nextLine(); int con=words(input, name); int lin=Linee(input, name); outpu(console,con,lin); }public static int words(Scanner input,String name){// count the words from input text file.int count= 0; while(input.hasNext()){String word=input.next(); count++; }return count; }public static int Linee(Scanner input,String name){ //count the line from input text fileint num=1; while(input.hasNextLine()){String word=input.nextLine(); num++; } return num;}public static void outpu(Scanner console,int con,int lin)throws FileNotFoundException{//create the output file System.out.println("what is the output file name? "); String hey=console.next(); PrintStream output = new PrintStream(new File(hey));output.println("total words= "+con); }public static void Character(String s){//count character withtout white space.int start=0; while(start<s.length()&&s.charAt(start)==' '){start++;}int stop=start;while(stop<s.length() && s.charAt(stop)!=' '){stop++;} }}

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question