Found 34493 Articles for Programming

How to divide an array into half in java?

Abhinaya
Updated on 19-Feb-2020 11:21:36

13K+ Views

Using the copyOfRange() method you can copy an array within a range. This method accepts three parameters, an array that you want to copy, start and end indexes of the range.You split an array using this method by copying the array ranging from 0 to length/2 to one array and length/2 to length to other.Exampleimport java.util.Arrays; import java.util.Scanner; public class SplittingAnArray {    public static void main(String args[]) {       Scanner s =new Scanner(System.in);       System.out.println("Enter the required size of the array ::");       int size = s.nextInt();       int [] myArray ... Read More

How to perform different commands over ssh with Python?

Rajendra Dharmkar
Updated on 18-Feb-2020 07:15:27

1K+ Views

The simplest way to use SSH using python is to use paramiko. You can install it using −$ pip install paramikoTo use paramiko, ensure that you have correctly set up SSH keys(https://confluence.atlassian.com/bitbucketserver/creating-ssh-keys-776639788.html) on the host machine and when running the python script, these keys are accessible. Once that is done use the following code to connect to a remote server using ssh −from paramiko import SSHClient ssh = SSHClient() ssh.load_system_host_keys() ssh.connect('user@server:path') ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command('ls') print(ssh_stdout) #print the output of ls commandYou can use the exec_command function to run any command supported by the server you're connected to over ... Read More

How to count unique elements in the array using java?

Ankitha Reddy
Updated on 30-Jul-2019 22:30:20

766 Views

The interface Set does not allow duplicate elements, therefore, create a set object and try to add each element to it using the add() method in case of repetition of elements this method returns false − If you try to add all the elements of the array to a Set, it accepts only unique elements − Example import java.util.Arrays; import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class CountingUniqueElements { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter the size ... Read More

How to use FTP in Python?

Rajendra Dharmkar
Updated on 18-Feb-2020 07:14:33

282 Views

You can use the ftplib module in Python. It allows you to write programs that perform a variety of automated FTP jobs. You can easily connect to a FTP server to retrieve files and process them locally.exampleimport ftplib ftp = ftplib.FTP('ftp.yourserver.com', 'yourusername', 'your@email.address') print "File List: " files = ftp.dir() print(files) ftp.cwd("/tmp") #change working directory to /tmpAbove code connects to a FTP server and prints the file list in the home directory of that server.

How to find numbers in an array that are greater than, less than, or equal to a value in java?

Srinivas Gorla
Updated on 16-Jun-2020 09:36:58

3K+ Views

You can find numbers in an array that are greater than, less than, or equal to a value as:ExampleLive Demopublic class GreaterOrLess {    public static void main(String args[]) {       int value = 65;       int[] myArray = {41, 52, 63, 74, 85, 96 };       System.out.println("Elements of the array that are equal to the given value are::");       for(int i = 0; i

How to store a 2d Array in another 2d Array in java?

Abhinanda Shri
Updated on 19-Feb-2020 11:22:53

3K+ Views

Create an array to which you want to store the existing array with the same length. A 2d array is an array of one dimensional arrays therefore, to copy (or, to perform any operation on) the elements of the 2d array you need two loops one nested within the other. Where, the outer loop is to traverse through the array of one dimensional arrays and, the inner loop is to traverse through the elements of a particular one dimensional array.Examplepublic class Copying2DArray {    public static void main(String args[]) {       int[][] myArray = {{41, 52, 63}, {74, ... Read More

How to copy a file to a remote server in Python using SCP or SSH?

Rajendra Dharmkar
Updated on 18-Feb-2020 07:10:47

13K+ Views

The easiest way to copy files from one server to another over ssh is to use the scp command. For calling scp you'd need the subprocess module. exampleimport subprocess p = subprocess.Popen(["scp", "my_file.txt", "username@server:path"]) sts = os.waitpid(p.pid, 0)You need the waitpid call to wait for the copying to complete.Another solution is to open a ssh connection and use the scp module.  examplefrom paramiko import SSHClient from scp import SCPClient ssh = SSHClient() ssh.load_system_host_keys() ssh.connect('user@server:path') with SCPClient(ssh.get_transport()) as scp:     scp.put('my_file.txt', 'my_file.txt') # Copy my_file.txt to the serverRead More

Can we overload the main method in Java?

radhakrishna
Updated on 30-Jul-2019 22:30:20

3K+ Views

Yes, we can overload the main method in Java, but When we execute the class JVM starts execution with public static void main(String[] args) method. Example Live Demo public class Sample{ public static void main(){ System.out.println("This is the overloaded main method"); } public static void main(String args[]){ Sample obj = new Sample(); obj.main(); } } Output This is the overloaded main method

How to copy files from one server to another using Python?

Rajendra Dharmkar
Updated on 16-Dec-2019 07:53:53

8K+ Views

The easiest way to copy files from one server to another over ssh is to use the scp command. For calling scp you'd need the subprocess module.For exampleimport subprocess p = subprocess.Popen(["scp", "my_file.txt", "username@server:path"]) sts = os.waitpid(p.pid, 0)You need the waitpid call to wait for the copying to complete.Another solution is to open a ssh connection and use the scp module.For examplefrom paramiko import SSHClient from scp import SCPClient ssh = SSHClient() ssh.load_system_host_keys() ssh.connect('user@server:path') with SCPClient(ssh.get_transport()) as scp:     scp.put('my_file.txt', 'my_file.txt') # Copy my_file.txt to the serverRead More

Why is method overloading not possible by changing the return type of the method only in java?

mkotla
Updated on 30-Jul-2019 22:30:20

2K+ Views

Overloading is the mechanism of binding the method call with the method body dynamically based on the parameters passed to the method call. If you observe the following example, it contains two methods with same name, different parameters and if you call the method by passing two integer values the first method will be executed and, if you call by passing 3 integer values then the second method will be executed.It is not possible to decide to execute which method based on the return type, therefore, overloading is not possible just by changing the return type of the method. Example ... Read More

Advertisements