Skip to main content

Posts

Change an extension to file in python

Program to change an extension of a file in python: import os import shutil def renamefiles():     filelist = os.listdir(r"source path here")     print(filelist)     os.chdir(r"source path here")     path = os.getcwd()     for filename in filelist:         if filename.endswith(".xml"):             print("Old Name - " + filename)             (prefix, sep, sffix) = filename.rpartition(".")             newfile = filename + '.ok'             if not filename.endswith(".ok"):                 os.rename(filename, newfile)                 print("New Name - " + newfile)                 os.chdir(path) # path to source directory src_dir = r'source path here' # path to destination directory...

Java Program to print Star patterns

 Java Star Pattern Programs: ================================================================= Patterns 1:  package javaPrograms; public class StarPattern { public static void main(String[] args) { //i for rows and j for columns       //row denotes the number of rows you want to print   int i, j, row=6;    //outer loop for rows   for(i=0; i<row; i++)    {    //inner loop for columns   for(j=0; j<=i; j++)    {    //prints stars    System.out.print("* ");    }    //throws the cursor in a new line after printing each line   System.out.println();    }      } } ================================================================= Pattern 2:  package javaPrograms; public class StarPattern1 { public static void main(String[] args) { for(int i=1;i<=4;i++) { ...

Java Program to check if Number is Armstrong or not

 Logic for  Armstrong   number :)  Armstrong Number An  Armstrong  number is a positive m-digit number that is equal to the sum of the m th  powers of their digits. It is also known as  pluperfect , or  Plus Perfect , or  Narcissistic  number. It is an OEIS sequence  A005188 . Let’s understand it through an example. Armstrong Number Example 1:  1 1  =  1 2:  2 1  =  2 3:  3 1  =  3 153:  1 3  + 5 3  + 3 3  = 1 + 125+ 27 =  153 125:  1 3  + 2 3  + 5 3  = 1 + 8 + 125 =  134 (Not an Armstrong Number) 1634:  1 4  + 6 4  + 3 4  + 4 4  = 1 + 1296 + 81 + 256 =  1643 //Armstrong number list:0,1,153,370,371,407,1634 //Eg 153 rest to 3(Total number of digit ) each digit if addition come original number. package javaPrograms; import java.util.Scanner; public class ArmstrongNumber { public static vo...

Java Program to reverse the Array elements

 package javaPrograms; import java.util.Scanner; public class ReverseArray { public static void main(String[] args) { Scanner sc = new Scanner (System.in); System.out.println("Enter the number of Elements::"); int n =sc.nextInt(); System.out.println("Enter the "+ n +" number of array elements"); int a[] = new int[n]; for(int i=0;i<n;i++) { a[i]=sc.nextInt(); } System.out.println("The reverse of array Elements are as follow"); for(int i=a.length-1;i>=0;i--) { System.out.println(a[i]); } } }

Java Program to find Maximum element from the Array

 package javaPrograms; import java.util.Scanner; public class MaximumElementInArray { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the Length of Array::"); int n = sc.nextInt(); System.out.println("Enter the "+n+" number of Array Element::"); int a[] = new int[n]; for(int i=0;i<n;i++) { a[i] =sc.nextInt(); } int max=a[0];    for(int i=1;i<a.length;i++) {    if(a[i]>max) {    max=a[i];    }    }    System.out.println("Maximum Element is::"+max); } }

Java Prgram to find the minimum element in the Array

 package javaPrograms; import java.util.Scanner; public class ArrayMinElement { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the Length of Array::"); int n = sc.nextInt(); System.out.println("Enter the "+n+" number of Array Element::"); int a[] = new int[n]; for(int i=0;i<n;i++) { a[i] =sc.nextInt(); } int min=a[0];    for(int i=1;i<a.length;i++) {    if(a[i]<=min) {    min=a[i];    }    }    System.out.println("Minimum Element is::"+min); } }

Java program to Sort the Array in ascending order

 package javaPrograms; import java.util.Scanner; public class ArrayAscending { public static void main(String[] args) { //Create object of scanner class Scanner sc = new Scanner(System.in); System.out.println("Enter the number:"); int n= sc.nextInt(); //Declare and initialize Array and other Required variables.. int a[] = new int [n];    int i,j,temp=0;   //Now get all array elements from user System.out.println("Enter" + n   +"number of array elements:  ");//5 for(i=0;i<n;i++) { a[i]=sc.nextInt(); } //Print all array elements System.out.println("All array elements are: ");//4 6 3 2 1 8 for(i=0;i<n;i++) { System.out.println(" "+a[i]); } //Now arrange array elements in ascending order for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(a[i]>a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } } //Print array ...