C# Program to Display Squarefeet of a House

/*
 * C# Program to Display Squarefeet of a House
 */
using System;
class pgm
{
    public static void Main()
    {
        int length, width, area;
        Console.Write ("Enter length of room in feet: ");
        length = Convert.ToInt32 (Console.ReadLine());
        Console.Write ( "Enter width of room in feet:");
        width = Convert.ToInt32(Console.ReadLine());
        area = length * width;
        Console.WriteLine ("Floor is " + area +  " square feet.");
        Console.ReadLine();
    }
}

C# Program to Find Greatest among 2 numbers

/*
 * C# Program to Find Greatest among 2 numbers
 */
using System;
class prog
{
    public static void Main()
    {
        int a, b;
        Console.WriteLine("Enter the Two Numbers : ");
        a = Convert.ToInt32(Console.ReadLine());
        b = Convert.ToInt32(Console.ReadLine());
        if (a > b)
        {
            Console.WriteLine("{0} is the Greatest Number", a);
        }
        else
        {
            Console.WriteLine("{0} is the Greatest Number ", b);
        }
        Console.ReadLine();
    }
}

C# Program to Illustrate LeftShift Operations

/*
 * C# Program to Illustrate LeftShift Operations
 */
using System;
class sample
{
    public static void Main()
    {
        int x = 1024 * 1024 * 1024;
        uint p = 1024 * 1024 * 1024;
        int y = -42;
        Console.WriteLine("LEFT SHIFT OPERATIONS :");
        Console.WriteLine("{0},{1},{2}", x, x * 2, x << 1);
        Console.WriteLine("{0},{1},{2}", p, p * 2, p << 1);
        Console.WriteLine("{0},{1},{2}", x, x * 4, x << 2);
        Console.WriteLine("{0},{1},{2}", p, p * 4, p << 2);
        Console.WriteLine("{0},{1},{2}", y, y * 1024 * 1024 * 64, x << 26);
        Console.ReadLine();
    }
}

C# Program to Display the ATM Transaction

/*
 * C# Program to Display the ATM Transaction
 */
using System;
class program
{
    public static void Main()
    {

        int amount = 1000, deposit, withdraw;
        int choice, pin = 0, x = 0;
        Console.WriteLine("Enter Your Pin Number ");
        pin = int.Parse(Console.ReadLine());
        while (true)
        {
            Console.WriteLine("********Welcome to ATM Service**************\n");
            Console.WriteLine("1. Check Balance\n");
            Console.WriteLine("2. Withdraw Cash\n");
            Console.WriteLine("3. Deposit Cash\n");
            Console.WriteLine("4. Quit\n");
            Console.WriteLine("*********************************************\n\n");
            Console.WriteLine("Enter your choice: ");
            choice = int.Parse(Console.ReadLine());
            switch (choice)
            {
            case 1:
                Console.WriteLine("\n YOUR BALANCE IN Rs : {0} ", amount);
                break;
            case 2:
                Console.WriteLine("\n ENTER THE AMOUNT TO WITHDRAW: ");
                withdraw = int.Parse(Console.ReadLine());
                if (withdraw % 100 != 0)
                {
                    Console.WriteLine("\n PLEASE ENTER THE AMOUNT IN MULTIPLES OF 100");
                }
                else if (withdraw > (amount - 500))
                {
                    Console.WriteLine("\n INSUFFICENT BALANCE");
                }
                else
                {
                    amount = amount - withdraw;
                    Console.WriteLine("\n\n PLEASE COLLECT CASH");
                    Console.WriteLine("\n YOUR CURRENT BALANCE IS {0}", amount);
                }
                break;
            case 3:
                Console.WriteLine("\n ENTER THE AMOUNT TO DEPOSIT");
                deposit = int.Parse(Console.ReadLine());
                amount = amount + deposit;
                Console.WriteLine("YOUR BALANCE IS {0}", amount);
                break;
            case 4:
                Console.WriteLine("\n THANK U USING ATM");
            break;
            }
        }
        Console.WriteLine("\n\n THANKS FOR USING OUT ATM SERVICE");
    }
 }

C# Program to Compare Two Dates

/*
 * C# Program to Campare Two Dates
 */
using System;
namespace DateAndTime
{
    class Program
    {
        static int Main()
        {
            DateTime sd = new DateTime(2010, 10, 12);
            Console.WriteLine("Starting Date : {0}", sd);
            DateTime ed = sd.AddDays(10);
            Console.WriteLine("Ending Date   : {0}", ed);
            if (sd < ed)
                Console.WriteLine("{0} Occurs Before {1}", sd, ed);
            Console.Read();
            return 0;

        }
    }
}

C# Program to Print a BinaryTriangle

/*
 * C# Program to Print a BinaryTriangle
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Program
{
    class Program
    {
        public static void Main(String[] args)
        {
            int p, lastInt = 0, input;
            Console.WriteLine("Enter the Number of Rows : ");
            input = int.Parse(Console.ReadLine());
            for (int i = 1; i <= input; i++)
            {
                for (p = 1; p <= i; p++)
                {
                    if (lastInt == 1)
                    {
                        Console.Write("0");
                        lastInt = 0;
                    }
                    else if (lastInt == 0)
                    {
                        Console.Write("1");
                        lastInt = 1;
                    }
                } Console.Write("\n");
            }
            Console.ReadLine();
        }
    }
}

PHP File Upload Script

<html>
 <head>
 <title>A File Upload Script</title>
 </head>
 <body>
 <div>
 <?php
 if ( isset( $_FILES['fupload'] ) ) {

     print "name: ".     $_FILES['fupload']['name']       ."<br />";
     print "size: ".     $_FILES['fupload']['size'] ." bytes<br />";
     print "temp name: ".$_FILES['fupload']['tmp_name']   ."<br />";
     print "type: ".     $_FILES['fupload']['type']       ."<br />";
     print "error: ".    $_FILES['fupload']['error']      ."<br />";

     if ( $_FILES['fupload']['type'] == "image/gif" ) {

         $source = $_FILES['fupload']['tmp_name'];
         $target = "upload/".$_FILES['fupload']['name'];
         move_uploaded_file( $source, $target );// or die ("Couldn't copy");
         $size = getImageSize( $target );

         $imgstr = "<p><img width=\"$size[0]\" height=\"$size[1]\" ";
         $imgstr .= "src=\"$target\" alt=\"uploaded image\" /></p>";

         print $imgstr;
     }
 }
 ?>
 </div>
 <form enctype="multipart/form-data"
     action="<?php print $_SERVER['PHP_SELF']?>" method="post">
 <p>
 <input type="hidden" name="MAX_FILE_SIZE" value="102400" />
 <input type="file" name="fupload" /><br/>
 <input type="submit" value="upload!" />
 </p>
 </form>
 </body>
 </html>

C# Program to Check whether the Entered Number is Even or Odd

/*
 * C# Program to Check whether the Entered Number is Even or Odd
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace check1
{
    class Program
    {
        static void Main(string[] args)
        {
            int i;
            Console.Write("Enter a Number : ");
            i = int.Parse(Console.ReadLine());
            if (i % 2 == 0)
            {
                Console.Write("Entered Number is an Even Number");
                Console.Read();
            }
            else
            {
                Console.Write("Entered Number is an Odd Number");
                Console.Read();
            }
        }
    }
}

C program to read name and marks of n number of students from user and store them in a file.

#include <stdio.h>
int main()
{
   char name[50];
   int marks, i, num;

   printf("Enter number of students: ");
   scanf("%d", &num);

   FILE *fptr;
   fptr = (fopen("C:\\student.txt", "w"));
   if(fptr == NULL)
   {
       printf("Error!");
       exit(1);
   }

   for(i = 0; i < num; ++i)
   {
      printf("For student%d\nEnter name: ", i+1);
      scanf("%s", name);

      printf("Enter marks: ");
      scanf("%d", &marks);

      fprintf(fptr,"\nName: %s \nMarks=%d \n", name, marks);
   }

   fclose(fptr);
   return 0;
}

Java Program to Concatenate Two Arrays

import java.util.Arrays;

public class Concat {

    public static void main(String[] args) {
        int[] array1 = {1, 2, 3};
        int[] array2 = {4, 5, 6};

        int aLen = array1.length;
        int bLen = array2.length;
        int[] result = new int[aLen + bLen];

        System.arraycopy(array1, 0, result, 0, aLen);
        System.arraycopy(array2, 0, result, aLen, bLen);

        System.out.println(Arrays.toString(result));
    }
}

Java Program to Add Two Dates

import java.util.Calendar;

public class AddDates {

    public static void main(String[] args) {

        Calendar c1 = Calendar.getInstance();
        Calendar c2 = Calendar.getInstance();
        Calendar cTotal = (Calendar) c1.clone();

        cTotal.add(Calendar.YEAR, c2.get(Calendar.YEAR));
        cTotal.add(Calendar.MONTH, c2.get(Calendar.MONTH) + 1); // Zero-based months
        cTotal.add(Calendar.DATE, c2.get(Calendar.DATE));
        cTotal.add(Calendar.HOUR_OF_DAY, c2.get(Calendar.HOUR_OF_DAY));
        cTotal.add(Calendar.MINUTE, c2.get(Calendar.MINUTE));
        cTotal.add(Calendar.SECOND, c2.get(Calendar.SECOND));
        cTotal.add(Calendar.MILLISECOND, c2.get(Calendar.MILLISECOND));

        System.out.format("%s + %s = %s", c1.getTime(), c2.getTime(), cTotal.getTime());

    }
}

Java Program to Convert String to Date

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class TimeString {

    public static void main(String[] args) {
        // Format y-M-d or yyyy-MM-d
        String string = "2017-07-25";
        LocalDate date = LocalDate.parse(string, DateTimeFormatter.ISO_DATE);

        System.out.println(date);
    }
}

Application For A Fresh Juice Shop In JAVA

class FreshJuice {
 enum FreshJuiceSize{ SMALL, MEDIUM, LARGE }
 FreshJuiceSize size;
}
public class FreshJuiceTest {
 public static void main(String args[]){
 FreshJuice juice = new FreshJuice();
 juice.size = FreshJuice.FreshJuiceSize.MEDIUM ;
 System.out.println("Size: " + juice.size);
 }
}

Java Program to Display Factors of a Number

public class Factors {

    public static void main(String[] args) {

        int number = 60;

        System.out.print("Factors of " + number + " are: ");
        for(int i = 1; i <= number; ++i) {
            if (number % i == 0) {
                System.out.print(i + " ");
            }
        }
    }
}

Java Program to Find G.C.D Using Recursion

public class GCD {

    public static void main(String[] args) {
        int n1 = 366, n2 = 60;
        int hcf = hcf(n1, n2);

        System.out.printf("G.C.D of %d and %d is %d.", n1, n2, hcf);
    }

    public static int hcf(int n1, int n2)
    {
        if (n2 != 0)
            return hcf(n2, n1 % n2);
        else
            return n1;
    }
}

Java Program to Find LCM of two Numbers

public class LCM {
    public static void main(String[] args) {

        int n1 = 72, n2 = 120, lcm;

        // maximum number between n1 and n2 is stored in lcm
        lcm = (n1 > n2) ? n1 : n2;

        // Always true
        while(true)
        {
            if( lcm % n1 == 0 && lcm % n2 == 0 )
            {
                System.out.printf("The LCM of %d and %d is %d.", n1, n2, lcm);
                break;
            }
            ++lcm;
        }
    }
}
When you run the program, t

Java Program to Find GCD of two Numbers

public class GCD {

    public static void main(String[] args) {

        int n1 = 81, n2 = 153, gcd = 1;

        for(int i = 1; i <= n1 && i <= n2; ++i)
        {
            // Checks if i is factor of both integers
            if(n1 % i==0 && n2 % i==0)
                gcd = i;
        }

        System.out.printf("G.C.D of %d and %d is %d", n1, n2, gcd);
    }
}

Simple Word Counter

import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class SimpleWordCounter {

public static void main(String[] args) {
try {
File f = new File("ciaFactBook2008.txt");
Scanner sc;
sc = new Scanner(f);
// sc.useDelimiter("[^a-zA-Z']+");
Map<String, Integer> wordCount = new TreeMap<String, Integer>();
while(sc.hasNext()) {
String word = sc.next();
if(!wordCount.containsKey(word))
wordCount.put(word, 1);
else
wordCount.put(word, wordCount.get(word) + 1);
}

// show results
for(String word : wordCount.keySet())
System.out.println(word + " " + wordCount.get(word));
System.out.println(wordCount.size());
}
catch(IOException e) {
System.out.println("Unable to read from file.");
}
}
}

C Program to reverse a given number using Recursive function

#include<stdio.h>
int main(){
   int num,reverse_number;

   //User would input the number
   printf("\nEnter any number:");
   scanf("%d",&num);

   //Calling user defined function to perform reverse
   reverse_number=reverse_function(num);
   printf("\nAfter reverse the no is :%d",reverse_number);
   return 0;
}
int sum=0,rem;
reverse_function(int num){
   if(num){
      rem=num%10;
      sum=sum*10+rem;
      reverse_function(num/10);
   }
   else
      return sum;
   return sum;
}

C Program to find prime numbers in a given range

#include <stdio.h>
int main()
{
   int num1, num2, flag_var, i, j;

   /* Ask user to input the from/to range
    * like 1 to 100, 10 to 1000 etc.
    */
   printf("Enter two range(input integer numbers only):");
   //Store the range in variables using scanf
   scanf("%d %d", &num1, &num2);

   //Display prime numbers for input range
   printf("Prime numbers from %d and %d are:\n", num1, num2);
   for(i=num1+1; i<num2; ++i)
   {
      flag_var=0;
      for(j=2; j<=i/2; ++j)
      {
         if(i%j==0)
         {
            flag_var=1;
            break;
         }
      }
      if(flag_var==0)
         printf("%d\n",i);
  }
  return 0;
}

C Program to find the Sum of First n Natural numbers

#include <stdio.h>
int main()
{
    int n, count, sum = 0;

    printf("Enter the value of n(positive integer): ");
    scanf("%d",&n);

    for(count=1; count <= n; count++)
    {
        sum = sum + count;
    }

    printf("Sum of first %d natural numbers is: %d",n, sum);

    return 0;
}

Java Program to find largest of three Numbers

public class JavaExample{

  public static void main(String[] args) {

      int num1 = 10, num2 = 20, num3 = 7;

      if( num1 >= num2 && num1 >= num3)
          System.out.println(num1+" is the largest Number");

      else if (num2 >= num1 && num2 >= num3)
          System.out.println(num2+" is the largest Number");

      else
          System.out.println(num3+" is the largest Number");
  }
}

Java Program to find area of Geometric figures using method Overloading

class JavaExample
{
    void calculateArea(float x)
    {
        System.out.println("Area of the square: "+x*x+" sq units");
    }
    void calculateArea(float x, float y)
    {
        System.out.println("Area of the rectangle: "+x*y+" sq units");
    }
    void calculateArea(double r)
    {
        double area = 3.14*r*r;
        System.out.println("Area of the circle: "+area+" sq units");
    }
    public static void main(String args[]){
        JavaExample obj = new JavaExample();
       
        /* This statement will call the first area() method
         * because we are passing only one argument with
         * the "f" suffix. f is used to denote the float numbers
         * 
         */
obj.calculateArea(6.1f);
   
/* This will call the second method because we are passing 
  * two arguments and only second method has two arguments
  */
obj.calculateArea(10,22);
   
/* This will call the second method because we have not suffixed
  * the value with "f" when we do not suffix a float value with f 
  * then it is considered as type double.
  */
obj.calculateArea(6.1);
    }
}

Java Program to Make a Calculator using Switch Case

import java.util.Scanner;

public class JavaExample {

    public static void main(String[] args) {

    double num1, num2;
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter first number:");

        /* We are using data type double so that user
         * can enter integer as well as floating point
         * value
         */
        num1 = scanner.nextDouble();
        System.out.print("Enter second number:");
        num2 = scanner.nextDouble();

        System.out.print("Enter an operator (+, -, *, /): ");
        char operator = scanner.next().charAt(0);

        scanner.close();
        double output;

        switch(operator)
        {
            case '+':
            output = num1 + num2;
                break;

            case '-':
            output = num1 - num2;
                break;

            case '*':
            output = num1 * num2;
                break;

            case '/':
            output = num1 / num2;
                break;

            /* If user enters any other operator or char apart from
             * +, -, * and /, then display an error message to user
             * 
             */
            default:
                System.out.printf("You have entered wrong operator");
                return;
        }

        System.out.println(num1+" "+operator+" "+num2+": "+output);
    }
}

Java Program to Find Factorial using For and While loop

public class JavaExample {

    public static void main(String[] args) {

    //We will find the factorial of this number
        int number = 5;
        long fact = 1;
        for(int i = 1; i <= number; i++)
        {
            fact = fact * i;
        }
        System.out.println("Factorial of "+number+" is: "+fact);
    }
}

Java program for bubble sort in Ascending & descending order

import java.util.Scanner;

class BubbleSortExample {
  public static void main(String []args) {
    int num, i, j, temp;
    Scanner input = new Scanner(System.in);

    System.out.println("Enter the number of integers to sort:");
    num = input.nextInt();

    int array[] = new int[num];

    System.out.println("Enter " + num + " integers: ");

    for (i = 0; i < num; i++) 
      array[i] = input.nextInt();

    for (i = 0; i < ( num - 1 ); i++) {
      for (j = 0; j < num - i - 1; j++) {
        if (array[j] > array[j+1]) 
        {
           temp = array[j];
           array[j] = array[j+1];
           array[j+1] = temp;
        }
      }
    }

    System.out.println("Sorted list of integers:");

    for (i = 0; i < num; i++) 
      System.out.println(array[i]);
  }
}

Java program to calculate area of Triangle

/**
 * @author: BeginnersBook.com
 * @description: Program to Calculate area of Triangle in Java
 * with user interaction. Program will prompt user to enter the 
 * base width and height of the triangle.
 */
import java.util.Scanner;
class AreaTriangleDemo {
   public static void main(String args[]) {   
      Scanner scanner = new Scanner(System.in);

      System.out.println("Enter the width of the Triangle:");
      double base = scanner.nextDouble();

      System.out.println("Enter the height of the Triangle:");
      double height = scanner.nextDouble();

      //Area = (width*height)/2
      double area = (base* height)/2;
      System.out.println("Area of Triangle is: " + area);      
   }
}

Java Program to calculate area and circumference of circle

/**
 * @author: BeginnersBook.com
 * @description: Program to calculate area and circumference of circle
 * with user interaction. User will be prompt to enter the radius and 
 * the result will be calculated based on the provided radius value.
 */
import java.util.Scanner;
class CircleDemo
{
   static Scanner sc = new Scanner(System.in);
   public static void main(String args[])
   {
      System.out.print("Enter the radius: ");
      /*We are storing the entered radius in double
       * because a user can enter radius in decimals
       */
      double radius = sc.nextDouble();
      //Area = PI*radius*radius
      double area = Math.PI * (radius * radius);
      System.out.println("The area of circle is: " + area);
      //Circumference = 2*PI*radius
      double circumference= Math.PI * 2*radius;
      System.out.println( "The circumference of the circle is:"+circumference) ;
   }
}

Java Program to Calculate Area of Rectangle

/**
 * @author: BeginnersBook.com
 * @description: Program to Calculate Area of rectangle
 */
import java.util.Scanner;
class AreaOfRectangle {
   public static void main (String[] args)
   {
   Scanner scanner = new Scanner(System.in);
   System.out.println("Enter the length of Rectangle:");
   double length = scanner.nextDouble();
   System.out.println("Enter the width of Rectangle:");
   double width = scanner.nextDouble();
   //Area = length*width;
   double area = length*width;
   System.out.println("Area of Rectangle is:"+area);
   }
}

Java program to calculate area of Square

/**
 * @author: BeginnersBook.com
 * @description: Program to Calculate Area of square.Program 
 * will prompt user for entering the side of the square.
 */
import java.util.Scanner;
class SquareAreaDemo {
   public static void main (String[] args)
   {
       System.out.println("Enter Side of Square:");
       //Capture the user's input
       Scanner scanner = new Scanner(System.in);
       //Storing the captured value in a variable
       double side = scanner.nextDouble();
       //Area of Square = side*side
       double area = side*side; 
       System.out.println("Area of Square is: "+area);
   }
}

Java Program to Reverse a Number

public class ReverseNumber {

    public static void main(String[] args) {

        int num = 1234, reversed = 0;

        while(num != 0) {
            int digit = num % 10;
            reversed = reversed * 10 + digit;
            num /= 10;
        }

        System.out.println("Reversed Number: " + reversed);
    }
}

Java Program to Calculate the Power of a Number

public class Power {

    public static void main(String[] args) {

        int base = 3, exponent = 4;

        long result = 1;

        while (exponent != 0)
        {
            result *= base;
            --exponent;
        }

        System.out.println("Answer = " + result);
    }
}

Java Program to Find all Roots of a Quadratic Equation

public class Quadratic {

    public static void main(String[] args) {

        double a = 2.3, b = 4, c = 5.6;
        double root1, root2;

        double determinant = b * b - 4 * a * c;

        // condition for real and different roots
        if(determinant > 0) {
            root1 = (-b + Math.sqrt(determinant)) / (2 * a);
            root2 = (-b - Math.sqrt(determinant)) / (2 * a);

            System.out.format("root1 = %.2f and root2 = %.2f", root1 , root2);
        }
        // Condition for real and equal roots
        else if(determinant == 0) {
            root1 = root2 = -b / (2 * a);

            System.out.format("root1 = root2 = %.2f;", root1);
        }
        // If roots are not real
        else {
            double realPart = -b / (2 *a);
            double imaginaryPart = Math.sqrt(-determinant) / (2 * a);

            System.out.format("root1 = %.2f+%.2fi and root2 = %.2f-%.2fi", realPart, imaginaryPart, realPart, imaginaryPart);
        }
    }
}

Java Program to Reverse a String using Recursion

public class JavaExample {

    public static void main(String[] args) {
        String str = "Welcome to Beginnersbook";
        String reversed = reverseString(str);
        System.out.println("The reversed string is: " + reversed);
    }

    public static String reverseString(String str)
    {
        if (str.isEmpty())
            return str;
        //Calling Function Recursively
        return reverseString(str.substring(1)) + str.charAt(0);
    }
}

Java Program to check Even or Odd number

import java.util.Scanner;

class CheckEvenOdd
{
  public static void main(String args[])
  {
    int num;
    System.out.println("Enter an Integer number:");

    //The input provided by user is stored in num
    Scanner input = new Scanner(System.in);
    num = input.nextInt();

    /* If number is divisible by 2 then it's an even number
     * else odd number*/
    if ( num % 2 == 0 )
        System.out.println("Entered number is even");
     else
        System.out.println("Entered number is odd");
  }
}

Java program to display prime numbers from 1 to 100 and 1 to n

class PrimeNumbers
{
   public static void main (String[] args)
   {
       int i =0;
       int num =0;
       //Empty String
       String  primeNumbers = "";

       for (i = 1; i <= 100; i++)         
       {     
          int counter=0;   
          for(num =i; num>=1; num--)
  {
             if(i%num==0)
     {
  counter = counter + 1;
     }
  }
  if (counter ==2)
  {
     //Appended the Prime number to the String
     primeNumbers = primeNumbers + i + " ";
  }
       }
       System.out.println("Prime numbers from 1 to 100 are :");
       System.out.println(primeNumbers);
   }
}

A sample of how to call methods in the same class.

/* CallingMethodsInSameClass.java
 *
 * illustrates how to call static methods a class
 * from a method in the same class
 */

public class CallingMethodsInSameClass
{
public static void main(String[] args) {
printOne();
printOne();
printTwo();
}

public static void printOne() {
System.out.println("Hello World");
}

public static void printTwo() {
printOne();
printOne();
}