1) Java Program to copy Sentence from file to another file
original.txt

CODE
import java.io.*;
import java.io.FileReader;
import javax.swing.*;
public class Main
{
// Function to reverse String
public static String reverse(String
sentence)
{
if (sentence.isEmpty())
{
return
sentence;
}
return
reverse(sentence.substring(1)) + sentence.charAt(0);
}
public static void main(String[] args) throws
IOException{
// Reading a File from given
path
FileReader fr=new
FileReader(new File("C:\\Users\\ChiTTi
ThaLLI\\Desktop\\original.txt"));
// Creating BufferReader to
Read data from file
BufferedReader br = new
BufferedReader(fr);
String s=br.readLine();
// Reading sentence from file
br.close(); // Closing
Buffered Reader
fr.close(); // Closing
FileReader
// Creating FileWriter
to create and write to a file
FileWriter fw=new
FileWriter("C:\\Users\\ChiTTi ThaLLI\\Desktop\\copy.txt");
String
reversed=reverse(s); // Calling function to reverse string, storing
to variable
fw.write(reversed);
// Writing reversed string to
file
fw.close();
// Closing FileWriter
JFrame f=new
JFrame(); // Creating JFrame to
display message
JOptionPane.showMessageDialog(f,"Successfully Copied"); //
Displaying message
System.exit(1);
// Terminating Java Program
}
}
OUTPUT

copy.txt

CODE in EDITOR

2) Java program to remove duplicates from array and print top 5 from array
CODE
import java.util.Scanner;
import java.util.Arrays;
public class Duplicate {
@SuppressWarnings("resource")
public static void main(String[] args) {
// Scanner class instance read user
input
Scanner scan=new
Scanner(System.in);
int array[]=new
int[10]; // Creating array of size 10
int n = array.length;
// Getting array size
for(int i=0;i<10;i++) {
array[i]=scan.nextInt();// Scanning 10 values from user
}
System.out.print("Original Array :
");
for(int i=0;i<10;i++) {
System.out.print(array[i]+" ");
}
System.out.println();
Arrays.sort(array);
System.out.print("Sorted Array :
");
for(int i=0;i<10;i++) {
System.out.print(array[i]+" ");
}
System.out.println();
n = removeDuplicates(array, n); //
Calling function to get nonduplicate values index
int[] array2=new
int[n]; // Creating new array to
store non duplicate values
for(int i=0;i<n;i++) {
array2[i]=array[n-i-1];
}
System.out.print("Array Without
Duplicates : ");
for(int i=0;i<n;i++) {
System.out.print(array2[i]+" ");
}
System.out.println();
int maxim=0;
if(array2.length>4) {
maxim=5;
}else {
maxim=array2.length;
}
System.out.print("Top 5 numbers
from Highest to Lowest : ");
for(int i=0;i<maxim;i++) {
System.out.print(array2[i]+" ");
}
System.out.println();
}
// Function to remove duplicate elements
// This function returns new size of
modified
// array.
static int removeDuplicates(int arr[], int
n)
{
if (n == 0 || n ==
1)
return n;
// To store index of
next unique element
int j = 0;
// Doing same as done in
Method 1
// Just maintaining
another updated index i.e. j
for (int i = 0; i <
n-1; i++)
if (arr[i] != arr[i+1])
arr[j++] = arr[i];
arr[j++] =
arr[n-1];
return j;
}
}
OUTPUT in CONSOLE
![** E * ? @- pre @ Console X <terminated> Duplicate [Java Application] C:\Program FilesVava\jdk-13\bin\javaw.exe (20-Feb-2020,](http://img.homeworklib.com/questions/8d4ba650-9e92-11ea-9cff-9590d3375c50.png?x-oss-process=image/resize,w_560)
CODE in EDITOR

3) Java program to count no.of Lines and no.of Words in a file
counting.txt

CODE
import java.io.*;
// Class to count lines and words in a file
public class Couting {
public static void main(String[] args) throws
IOException{
// Creating a FileReader instance
with given file path
FileReader fr=new FileReader(new
File("C:\\Users\\ChiTTi ThaLLI\\Desktop\\counting.txt"));
// Creating BufferedReader to read
data from file
BufferedReader br = new
BufferedReader(fr);
String s;
// String to store data
int lines_count=0;
// Variable to store lines
count
int word_count=0;
// Variable to store word
count
while((s = br.readLine()) !=
null){ // Loop until reaches END OF
FILE
lines_count=lines_count+1;
// Incrementing Lines count
if(!(s.equals("")))
// Checking line is not
empty
{
String[] words = s.split(" "); //
Splitting string and store words into array
word_count=word_count+words.length; //
Incrementing word count by size of array above
}
}
br.close(); // Closing
bufferedreader
fr.close(); // CLosing file
reader
// Printing Lines count and Word
count
System.out.println("Lines count in
File: "+lines_count);
System.out.println("Word count in
File: "+word_count);
}
}
OUTPUT in CONSOLE
![Console X <terminated> Couting [Java Application] C:\Program FilesVava Lines count in File: 4 Word count in File: 12](http://img.homeworklib.com/questions/8e5cc3b0-9e92-11ea-bef9-dfc29ab9cecf.png?x-oss-process=image/resize,w_560)
CODE IN EDITOR

Feel free to ask any doubts in the comment section below
NOTE: Could you Please Consider my Efforts on this work and Give UP VOTE.
Thank YOU : )
Part B: Java Programming Problems. Choose 2 of the following problems. Each solution is worth 20...
JAVA programming The task of parsing a file for correctness is an essential part of any programmer toolkit. The check for a balanced set of brackets in a file a Stack can be used and the following algorithm: • The source file is read character by character • Each time an opening '{' is read it is pushed onto the stack • Each time a closing '}' is read the stack is popped • If the stack is empty when...
Word count. A common utility on Unix/Linux systems. This program counts the number of lines, words (strings of characters separated by blanks or new lines), and characters in a file (not including blank spaces between words). Write your own version of this program. You will need to create a text file with a number of lines/sentences. The program should accept a filename (of your text file) from the user and then print three numbers: The count of lines/sentences The count...
Prelab Exercises Your task is to write a Java program that will print out the following message (including the row of equal marks): Computer Science, Yes!!!! ========================= An outline of the program is below. Complete it as follows: a. In the documentation at the top, fill in the name of the file the program would be saved in and a brief description of what the program does. b. Add the code for the main method to do the printing. //...
I need help writing these 2 programs please include all the indents :) In this programming challenge you are to create two Python programs: randomwrite.py andrandomread.py. One program, randomwrite.py, is to write a set of random numbers to a file. The second program, randomread.py, is to read a set of random numbers from a file, counts how many were read, displays the random numbers, and displays the total count of random numbers. Random Number File Writer (randomwrite.py) Create a program...
import java.util.Scanner; // TASK #1 Add the file I/O import statement here /** This class reads numbers from a file, calculates the mean and standard deviation, and writes the results to a file. */ public class StatsDemo { // TASK #1 Add the throws clause public static void main(String[] args) { double sum = 0; // The sum of the numbers int count = 0; // The number of numbers added double mean = 0; // The average of the...
Using the Design Recipe, write an algorithm for each of the following programming problems, showing all work (i.e., Contract, Purpose Statement, Examples and Algorithm): 5.Write a program that reads two times in military format (e.g., 0900, 1730) and prints the number of hours and minutes between the two times. Note that the first time can come before or after the second time. 6.An online bank wants you to create a program that shows prospective customers how their deposits will grow....
Choose 3 of 5 Problems to Solve
Need Soon as possible
Choose 3 of5 Problems to Solve (20 Point/Each) Problem l: Triangle Printing Program: Write an application that prints a right triangle with 1 to 8 rows. Prompt the user to enter an odd number in the range of 1 to 8 to specify the number of rows in the diamond. Add a validation loop to ensure the user does not enter an even number or a number outside the...
Write a Java Program that performs the following functionalities: and you can use if statements, cases, and string methods Enter a new main sentence Find a String Find all incidents of a String Find and Replace a String Replace all the incidents of a String Count the number of words Count a letter’s occurrences Count the total number of letters Delete all the occurrences of a word Exit The program will display a menu with each option above, and then...
** Language Used : Python ** PART 2 : Create a list of unique words This part of the project involves creating a function that will manage a List of unique strings. The function is passed a string and a list as arguments. It passes a list back. The function to add a word to a List if word does not exist in the List. If the word does exist in the List, the function does nothing. Create a test...
Kindly solve this using C PROGRAMMING ONLY.
4. Write a program marks.c which consists of a main function and three other functions called. readmarks , changemarks (, and writemarks() The program begins by calling the function readmarks () to read the input file marksin. txt which consists of a series of lines containing a student ID number (an integer) and a numeric mark (a float). Once the ID numbers and marks have been read into arrays (by readmarks () the...