Posts

Finding the maximum element in a list:

For finding the maximum element in a list: // C++ program to demonstrate the use of std::max #include<iostream> #include<algorithm> using namespace std; // Defining the binary function bool comp(int a, int b) {  return (a < b); } int main() {   int a=10;   int b=20;   int c=30;   int d=40;   int e=50;  // Finding the largest of all the numbers  cout << std::max({a, b, c, d, e},comp) << "\n"; return 0; } 

For loop C++

A  for  loop is a programming language statement which allows code to be repeatedly executed. The syntax for this is for ( <expression_1> ; <expression_2> ; <expression_3> ) <statement> expression_1  is used for intializing variables which are generally used for controlling terminating flag for the loop. expression_2  is used to check for the terminating condition. If this evaluates to false, then the loop is terminated. expression_3  is generally used to update the flags/variables. A sample loop will be for(int i = 0; i < 10; i++) { ... } Input Format You will be given two positive integers,   and   ( ), separated by a newline. Output Format For each integer   in the interval   : If  , then print the English representation of it in lowercase. That is "one" for  , "two" for  , and so on. Else if   and it is an even number...

Blockchain-program(easy)

A simple and very old method of sending secret messages is the substitution cipher. You might have used this cipher with your friends when you were a kid. Basically, each letter of the alphabet gets replaced by another letter of the alphabet. For example, every 'a' get replaced with an 'X', and every 'b' gets replaced with a 'Z', etc. Write a program thats ask a user to enter a secret message. Encrypt this message using the substitution cipher and display the encrypted message. Then decryped the encrypted message back to the original message. You may use the 2 strings below for  your subsitition. For example, to encrypt you can replace the character at position n in alphabet with the character at position n in key. To decrypt you can replace the character at position n in key with the character at position n in alphabet. Have fun! And make the cipher stronger if you wish! Currently the cipher only substitutes letters - you could easily...

Kotlin basics_habijabi -variable to hashmap

Kotlin basics_habijabi fun main(args : Array ) { // println("Enter a  Number") //    var x:Int=readLine()!!.toInt() // println("Enter a  Number") //    var y:Int=readLine()!!.toInt() // println(x+y) // // println("Enter number") // var x:Int=readLine()!!.toInt() // // when(x) // { // 1->println("A") // 2->println("B") // in 3..5 -> println("C") // // else -> println("D") // // } //var x:Int // while(x<=5){ // println(x) // x++ // } // for(x in 1..10){ // print(x) // print(" ") // } // // println() // // for(y in 10 downTo 1){ // print(y) // print(" ") // } // println() // for( z in 1..10 step 3){ // print(z) // print(" ") // } var bloodGroup=arrayOf("sifat","abc","def") for( x in bloodGroup) println(x) println(bloodGroup[0]) var bo...

Bubble Sort Algorithm in java

Image
Bubble Sort Algorithm package one; public class One { public static void main(String[] args) { // TODO Auto-generated method stub int[] intArray= {20,35,-15,7,55,1,-27}; for(int lastUnsortedIndex=intArray.length-1;lastUnsortedIndex >0;lastUnsortedIndex--) { for(int i=0;i<lastUnsortedIndex;i++) { if(intArray[i]>intArray[i+1]) { swap(intArray,i,i+1); } } } for(int i=0;i<intArray.length;i++) { System.out.print(intArray[i]+"  "); } } public static void swap(int [] array,int i,int j) { if(i==j) { return; } int temp=array[i]; array[i]=array[j]; array[j]=temp; } }

StringBuffer In Java

StringBuffer In Java: package one; public class StringBuffer { public static void main(String[] args) { java.lang.StringBuffer sb=new java.lang.StringBuffer("Hello ");  System.out.println(sb.capacity()); sb.append("Java"); System.out.println(sb); sb.insert(2," haha "); System.out.println(sb); sb.replace(1, 4, "huhuhuhu"); System.out.println(sb); sb.ensureCapacity(10); System.out.println(sb.capacity()); sb.delete(1, 18); System.out.println(sb); System.out.println(sb.capacity()); sb.reverse(); System.out.println(sb); }  } 

Convert LinkList To ArrayList in Java

Convert LinkList To ArrayList in Java: package one; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; public class LinkToArray { public static void main(String[] args) {     LinkedList<String> linkedlist = new LinkedList<String>();     linkedlist.add("Sifat");     linkedlist.add("mohaiminur"); linkedlist.add("huda"); linkedlist.add("sakib"); linkedlist.add("robi"); List<String> list = new ArrayList<String>(linkedlist); for (String str : list){    System.out.println(str); } } }