NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package Pl2;
import java.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.*;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Scanner;
import javax.swing.JOptionPane;

public class pl2 {



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

File afile =new File("decimal.txt");
File bfile =new File("edited.java");

InputStream inStream = new FileInputStream(afile);
OutputStream outStream = new FileOutputStream(bfile);

PrintWriter pw=new PrintWriter(bfile);
Scanner m = new Scanner(bfile);

try{

byte[] buffer = new byte[1024];

int length;

while ((length = inStream.read(buffer)) > 0){

outStream.write(buffer, 0, length);
}

}catch(IOException e){
e.printStackTrace();
}


//replace system with joption
while (m.hasNext())
{
String line = m.nextLine();
pw.println(line.replaceAll("System.out.print", "JOptionPane.showMessageDialog"));

}

//count number of words
Scanner sc = new Scanner(afile);
{
int count=0;
while(sc.hasNext())
{
sc.next();
count++;
}
System.out.println("Number of words: " + count);

}

//count number of chars
Scanner in = new Scanner(afile);
int chars = 0;
while(in.hasNext()) {
String line = in.nextLine();
chars += line.length();
}
System.out.println("Number of chars: " + chars);

//count number of keywords
int c=0;
Scanner txtscan = new Scanner("keywords.txt");
Scanner ex = new Scanner(afile);
while(txtscan.hasNext())
{
String st = ex.next();
String st1 = txtscan.next();
if(st1.equals(st))
{
c++;
}
}
System.out.println("Number of keywords: " + c);

//count number of spaces
Scanner scan = new Scanner(afile);
Scanner scan1 = new Scanner(afile);
int counter1 = 0;
int counter2= 0;
while (scan.hasNextLine())
{
scan.nextLine();
counter1++;
}
while (scan1.hasNextLine())
{
scan1.next();
counter2++;
}
System.out.println("Number of characters spaces: " + counter1 + "||" + "Number of spaces:" + counter2);

//count number of (for)
String word1 = "for";
int word1Count = 0;
Scanner s = new Scanner(afile);
while (s.hasNext())
{
String line = s.next();
if (line.indexOf("for") != -1)
word1Count++;
}
System.out.println("for count: " + word1Count);

//count number of (if)
String word2 = "for";
int word2Count = 0;
Scanner s1 = new Scanner(afile);
while (s1.hasNext())
{
String line = s1.next();
if (line.indexOf("if") != -1)
word2Count++;
}
System.out.println("if count: " + word2Count);


//count number of (if)
String word3 = "for";
int word3Count = 0;
Scanner s2 = new Scanner(afile);
while (s1.hasNext())
{
String line = s2.next();
if (line.indexOf("while") != -1)
word3Count++;
}
System.out.println("while count: " + word3Count);
System.out.println();



pw.close();
inStream.close();
outStream.close();

}







}





     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.