Active in Case of Technology

Read More

Technoledgetree

Active in Case of Technology
Read More

Project Spark

Microsoft Project Spark Launched
Read More

Google Adwords Makeover

Google Announced AdWords Is Getting Makeover
Read More

Windows 10 Event

Windows 10 Launch Event
Read More

Technoledgetree Admin

CEO @ Technoledgetree

Friday, February 24, 2017

Factorial Program - Recursive and Non-Recursive

/**
 * @author Technoledgetree
 */
public class FactorialTechnoledgetree {
public static void main(String[] args) {

int n=5,fact=1;
for(int i=1;i<=n;i++)
fact*=i;
System.out.println("Factorial of "+n+" is "+fact);
System.out.println("===============Recursively==============");
fact=findFactorial(n);
System.out.println("Factorial of "+n+" is "+fact);
}
public static int findFactorial(int num){
if (num == 0)  
   return 1;  
else  
   return(num * findFactorial(num-1));
}

}

/*OUTPUT
Factorial of 5 is 120
===============Recursively==============
Factorial of 5 is 120
*/
Read More

String Reversal program in java [various ways]

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

/**
 * @author Technoledgetree
 */
public class StringReversalTechnoledgetree {
String reverse="";
public static void main(String[] args) {
String str = new String("Technoledgetree");
System.out.println("=============Using Character Array=========");
char [] strChar = str.toCharArray();
for(int i=((strChar.length)-1);i>=0;i--)
System.out.print(strChar[i]);
System.out.println("\n=============Using StringBuilder=========");
StringBuilder sb = new StringBuilder();
sb.append(str);
sb=sb.reverse();
for(int i=0;i<sb.length();i++)
System.out.print(sb.charAt(i));
System.out.println("\n=============Using Collection=========");
List<Character> charList= new LinkedList<>();
    for(char c: strChar)
    charList.add(c);
    Collections.reverse(charList);
    ListIterator listIterator = charList.listIterator();
    while(listIterator.hasNext())
    System.out.print(listIterator.next());
    System.out.println("\n=============Using Recursion=========");
    StringReversalTechnoledgetree srt = new StringReversalTechnoledgetree();
    System.out.println(srt.reverseString(str));
}
    public String reverseString(String str){
       
        if(str.length() == 1){
            return str;
        } else {
            reverse += str.charAt(str.length()-1) + reverseString(str.substring(0,str.length()-1));
            return reverse;
        }
    }
}

/*OUTPUT

 =============Using Character Array=========
eertegdelonhceT
=============Using StringBuilder=========
eertegdelonhceT
=============Using Collection=========
eertegdelonhceT
=============Using Recursion=========
eertegdelonhceT

*/

Read More

Fibonacci Series in Java using Recursion and without using Recursion

/**
 * @author Technoledgetree
 *
 * A series of numbers in which each number ( Fibonacci number ) is the sum of the two preceding numbers.
 * The next number is found by adding up the two numbers before it.
 */
public class FibonacciTechnoledgetree {

public static void main(String[] args) {
int num1=0,num2=1,num3,i,limit=10;    //first 2 numbers 0,1 are fixed.
System.out.println("=============Without Recursion==========");
System.out.print(num1+" "+num2);
for(i=2;i<limit;++i)  
{  
 num3=num1+num2;  
 System.out.print(" "+num3);  
 num1=num2;  
 num2=num3;  
}
System.out.println();
System.out.println("=============Recursively==========");
System.out.print("0 1");
printRecursiveFibonacci(limit,0,1);
}
static void printRecursiveFibonacci(int limit,int first,int second){
int sum;
   if(limit>2){
        sum = first + second;
        System.out.print(" "+sum);
        first = second;
        second = sum;
        printRecursiveFibonacci(limit-1,first,second);
   }
}

}

/*OUTPUT

=============Without Recursion==========
0 1 1 2 3 5 8 13 21 34
=============Recursively==========
0 1 1 2 3 5 8 13 21 34

*/
Read More

Wednesday, February 22, 2017

Pattern Program Practice in Java

import java.util.Scanner;

/**
 * @author Technoledgetree
 */
public class PatternPracticeTechnoledgetree {

public static void main(String[] args) {
int n=4; //no of lines
System.out.println("Pattern 1");
for(int i=0;i<n;i++){
for(int j=0;j<i;j++){
System.out.print("*");
}
System.out.println("");
}

System.out.println("Pattern 2");
for(int i=0;i<n;i++){
for(int j=0;j<n-i-1;j++){
System.out.print(" ");
}
for(int k=0;k<i;k++){
System.out.print("*");
}
System.out.println("");
}

System.out.println("Pattern 3");
for(int i=0;i<n;i++){
for(int k=0;k<n-i-1;k++){
System.out.print(" ");
}
for(int k=0;k<=i;k++){
System.out.print(k+1);
}
for(int k=i-1;k>=0;k--){
System.out.print(k+1);
}
System.out.println("");
}

System.out.println("Pattern 4");
for(int i=0;i<n;i++){
for(int k=0;k<n-i-1;k++){
System.out.print(" ");
}
for(int k=0;k<=i;k++){
System.out.print(k+1);
}
for(int k=i-1;k>=0;k--){
System.out.print(k+1);
}
System.out.println("");
}
for(int i=0;i<=n-2;i++){
for(int k=0;k<=i;k++){
System.out.print(" ");
}
for(int k=0;k<n-i-2;k++){
System.out.print(k+1);
}
for(int k=n-i-2;k>=0;k--){
System.out.print(k+1);
}
System.out.println("");
}

System.out.println("Pattern 5");
System.out.println("123454321");
for(int i=0;i<=n;i++){
for(int j=1;j<=n-i;j++){
System.out.print(j);
}
System.out.print(" ");
for(int j=n-i;j>=1;j--){
System.out.print(j);
}
System.out.println("");
}

System.out.println("Pattern 6");
int o=1,z=1,t=0,row=4;
for(int i=1;i<=row;i++){
if(i%2==0){
z=o;
}else{t=o+i-1;}
for(int j=1;j<=i;j++){
if(i%2==0){
System.out.print(z+i-1);
z--;
}
else{
System.out.print(t);t--;
}
if(j!=i){
System.out.print("*");
}
o++;
}System.out.println();
}

System.out.println("Pattern 7");
int r=1,s=0,rows=4;
for(int i=1;i<=rows;i++){
if(i%2==0){
s=r;
}
for(int j=1;j<=i;j++){
if(i%2==0){
System.out.print(s+i-1);
s--;
}
else{
System.out.print(r);
}
if(j!=i){
System.out.print("*");
}
r++;
}System.out.println();
}

System.out.println("Pattern 8");
Scanner scanner = new Scanner(System.in);
System.out.println("Enter number of rows: ");
n=scanner.nextInt();
for(int i=0;i<n;i++){
for(int k=0;k<n-i-1;k++){
System.out.print(" ");
}
for(int k=0;k<=i;k++){
System.out.print("*");
}
for(int k=i-1;k>=0;k--){
System.out.print("*");
}
System.out.println("");
}
for(int i=0;i<=n-2;i++){
for(int k=0;k<=i;k++){
System.out.print(" ");
}
for(int k=0;k<n-i-2;k++){
System.out.print("*");
}
for(int k=n-i-2;k>=0;k--){
System.out.print("*");
}
System.out.println("");
}

}

}

/*OUTPUT
Pattern 1

*
**
***
Pattern 2
 
  *
 **
***
Pattern 3
   1
  121
 12321
1234321
Pattern 4
   1
  121
 12321
1234321
 12321
  121
   1
Pattern 5
123454321
1234 4321
123 321
12 21
1 1

Pattern 6
1
3*2
6*5*4
10*9*8*7
Pattern 7
1
3*2
4*5*6
10*9*8*7
Pattern 8
Enter number of rows:
4
   *
  ***
 *****
*******
 *****
  ***
   *

*/
Read More

Sunday, February 19, 2017

Regular Expression Practice

import java.util.regex.Pattern;
/**
 * @author Rahul
 */
public class RegExPracice {

public static void main(String[] args) {

System.out.println(Pattern.matches("[amn]","abc"));
System.out.println(Pattern.matches("[amn]","a"));
System.out.println(Pattern.matches("[ammmna]","amn"));

String str = "This is Technoledgetree. Active In Case of technology.";
String _str = str.replaceAll("\\s", "");
System.out.println(_str);
}

}

/*OUTPUT:
        false
true
false
ThisisTechnoledgetree.ActiveInCaseoftechnology.
*/

Read More

Condition Control Practice

/**
 * @author Technoledgetree
 */
public class LoopPracticeTechnoledgetree {

public static void main(String[] args) {

int number = 5;
for(int p=1;p<10;++p)
for(int q=1;q<11;q++)
for(int r=1;r<12;++r)
number = number+1; //line 12
//if(((p%5)==0) && ((q%4)==0) && ((r%6)==0))
System.out.println(number);
}

}

/* Output: 995
 *
 * if line 12 is replaced by:
 *  
 *   if(((p%5)==0) && ((q%4)==0) && ((r%6)==0))
 *  
 * the output will be:
 *   5
 *   5
 */  

Read More

Thursday, October 6, 2016

Pixel by Google

Google is going to launch a new smartphone with fabulous features. Checkout the introductory video:


Booking will start on 13th October` 2016. Stay in the know.



For more details and subscription of launching updates logon to : https://madeby.google.com/phone/

Image courtesy: Google
Video courtesy: Youtube
Read More

Social Profiles

Twitter Facebook Google Plus LinkedIn RSS Feed Email Pinterest

Live Viewers

Popular Posts