
1:- java program to copy the contents of one file to another file(input the file names using command-line arguments).
2:- java program to perform insertion,updation,deltion and selection operation on the database.
3:-java program to find the repeated digits in a given number.

Hello Friend,
Try these codes:
1)
import java.io.*;
public class CopyFile {
private static void copyfile(String srcfile,String destfile) {
try {
File f1 = new File(srcfile);
File f2 = new File(destfile);
InputStream in = new FileInputStream(f1);
OutputStream out = new FileOutputStream(f2, true);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
System.out.println("File copied.");
} catch (Exception ex) {
System.out.println(ex);
}
}
public static void main(String[] args)throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Source File: ");
String srcFile=reader.readLine();
System.out.println("Desination File: ");
String destFile=reader.readLine();
copyfile(srcFile,destFile);
}
}
2)
import java.sql.*;
class DatabaseOperations{
public static void main(String[] args){
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
Statement st = con.createStatement();
String name="roseindia";
String address="delhi";
int i = st.executeUpdate("INSERT INTO data(name, address) VALUES ('"+name+"','"+address+"')");
System.out.println("Data is inserted!");
int j=st.executeUpdate("update data set name='rose' where id='1'");
System.out.println("Data is updated!");
ResultSet rs=st.executeQuery("select * from data");
while(rs.next()){
System.out.println(rs.getString("name")+" "+rs.getString("address"));
}
int k=st.executeUpdate("delete from data where id='1'");
System.out.println("One row is deleted!");
}
catch(Exception e){
e.printStackTrace();
}
}
}
For the above code, we have created a table named 'data' in the database:
CREATE TABLE `data` (
`id` bigint(30) NOT NULL auto_increment,
`name` varchar(255) default NULL,
`address` varchar(255) default NULL,
PRIMARY KEY (`id`)
)
3)
import java.util.*;
class CountRepeatedNumber {
public static void main(String[] args) throws Exception{
Scanner input=new Scanner(System.in);
System.out.print("Enter number of multiple digits: ");
long num=input.nextLong();
String st=Long.toString(num);
char[]third =st.toCharArray();
for(int counter =0;counter<third.length;counter++){
char ch= third[counter];
int count=0;
for ( int i=0; i<third.length; i++){
if (ch==third[i])
count++;
}
boolean flag=false;
for(int j=counter-1;j>=0;j--){
if(ch==third[j])
flag=true;
}
if(!flag){
if(count>1){
System.out.println("Number "+ch+" is repeated "+count+" times ");
}
}
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.