Author Topic: Java Character counter from txtfile  (Read 924 times)

0 Members and 1 Guest are viewing this topic.

Offline Packment

  • NULL
  • Posts: 2
  • Cookies: 0
    • View Profile
Java Character counter from txtfile
« on: June 20, 2014, 12:18:14 pm »
This code have error somewhere around dnt knw what to do next
Please help me out

Code: [Select]
Import java.io.*;
Import java.util.Scanner;


Public class txtCharacter{
Public static Scanner kb = new Scanner;


Public static void  main(String args[])throws IOException{


  .   Scanner in = new Scanner(new FileReader("file locatio");
      char Character;


      System.out.println("Enter character to count");
      Character = kb.nextLineCharAt(0);


  while(in.hasNext){
  .  String line = in.readLine();
  .  int count;
     if(Character=!' '){
         counter++;
       }
  }
System.out.println("The number of occurrence: "+ count);
 }
In.close();
}
« Last Edit: June 20, 2014, 02:56:25 pm by Kulverstukas »

Offline ThePH30N1X

  • Peasant
  • *
  • Posts: 50
  • Cookies: 18
  • Java Programmer
    • View Profile
Re: Java Character counter from txtfile
« Reply #1 on: June 20, 2014, 12:51:01 pm »
Code: (Java) [Select]
import java.io.*;
import java.util.Scanner;


public class txtCharacter {

public static Scanner kb = new Scanner(System.in);


public static void main(String args[])throws IOException{


  .   Scanner in = new Scanner(new FileReader("file locatio"));
      char Character;


      System.out.println("Enter character to count");
      Character = kb.nextLineCharAt(0);


  while(in.hasNext){
    String line = in.readLine();
    int count;
     if(Character != ' '){
         count++;
       }
  }
System.out.println("The number of occurrence: "+ count);
 }
in.close();
}
Try that. I haven't tested it though.

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: Java Character counter from txtfile
« Reply #2 on: June 20, 2014, 03:05:45 pm »
This code have error somewhere around dnt knw what to do next
Please help me out

Code: [Select]
Import java.io.*;
Import java.util.Scanner;


Public class txtCharacter{
Public static Scanner kb = new Scanner;


Public static void  main(String args[])throws IOException{


  .   Scanner in = new Scanner(new FileReader("file locatio");
      char Character;


      System.out.println("Enter character to count");
      Character = kb.nextLineCharAt(0);


  while(in.hasNext){
  .  String line = in.readLine();
  .  int count;
     if(Character=!' '){
         counter++;
       }
  }
System.out.println("The number of occurrence: "+ count);
 }
In.close();
}

Where did you get this pile of shit from?
Seriously, this is worse than any code of any programming beginner in Java. It looks like copy&pasted from code in another language with an effortless try to transform it to Java. Learn the basics about Java and you might get anywhere.
« Last Edit: June 20, 2014, 03:08:34 pm by Deque »