Tuesday, 20 January 2015

Java Program To Print Multiplication Table



import java.util.Scanner;

class MultiplicationTable
{
   public static void main(String args[])
   {
      int n, c;
      System.out.println("Enter an integer to print it's multiplication table");
      Scanner in = new Scanner(System.in);
      n = in.nextInt();
      System.out.println("Multiplication table of "+n+" is :-");

      for ( c = 1 ; c <= 10 ; c++ )
         System.out.println(n+"*"+c+" = "+(n*c));
   }
}

Java Program To Print Alphabets



class Alphabets
{
   public static void main(String args[])
   {
      char ch;

      for( ch = 'a' ; ch <= 'z' ; ch++ )
         System.out.println(ch);
   }
}

Java "while" Loop



import java.util.Scanner;

class WhileLoop {
  public static void main(String[] args) {
    int n;

    Scanner input = new Scanner(System.in);
    System.out.println("Input an integer");

    while ((n = input.nextInt()) != 0) {
      System.out.println("You entered " + n);
      System.out.println("Input an integer");
    }

    System.out.println("Out of loop");
  }
}

Java "for" Loop

Simple for loop example in Java

class ForLoop {
  public static void main(String[] args) {
    int c;

    for (c = 1; c <= 10; c++) {
      System.out.println(c);
    }
  }
}





Java for loop example to print stars in console


class Stars {
  public static void main(String[] args) {
    int row, numberOfStars;

    for (row = 1; row <= 10; row++) {
      for(numberOfStars = 1; numberOfStars <= row; numberOfStars++) {
        System.out.print("*");
      }
      System.out.println(); // Go to next line
    }
  }
}

Java if-else Program

import java.util.Scanner;
 
class IfElse {
  public static void main(String[] args) {
    int marksObtained, passingMarks;
 
    passingMarks = 40;
 
    Scanner input = new Scanner(System.in);
 
    System.out.println("Input marks scored by you");
 
    marksObtained = input.nextInt();
 
    if (marksObtained >= passingMarks) {
      System.out.println("You passed the exam.");
    }
    else {
      System.out.println("Unfortunately you failed to pass the exam.");
    }
  }
}
 

Hello World

class HelloWorld
{
   public static void main(String args[])
   {
      System.out.println("Hello World");
   }
}

 

Download Hello world program class file.

 
 

Sunday, 18 January 2015

Link List Program

#include<stdio.h>
#include<conio.h>
#include<alloc.h>
//-------------------------------------------------
struct node
{
int data;
struct node *next;
}*start=NULL;
//------------------------------------------------------------

void creat()
{
char ch;
 do
 {
  struct node *new_node,*current;

  new_node=(struct node *)malloc(sizeof(struct node));

  printf("nEnter the data : ");
  scanf("%d",&new_node->data);
  new_node->next=NULL;

  if(start==NULL)
  {
  start=new_node;
  current=new_node;
  }
  else
  {
  current->next=new_node;
  current=new_node;
  }

 printf("nDo you want to creat another : ");
 ch=getche();
 }while(ch!='n');
}
//------------------------------------------------------------------

void display()
{
struct node *new_node;
 printf("The Linked List : n");
 new_node=start;
 while(new_node!=NULL)
   {
   printf("%d--->",new_node->data);
   new_node=new_node->next;
   }
  printf("NULL");
}
//----------------------------------------------------
void main()
{
create();
display();
}
//----------------------------------------------------

Enter the data : 10
Do you want to creat another :  y
Enter the data : 20
Do you want to creat another : y

Enter the data : 30
Do you want to creat another : n

The Linked List :
10--->20--->30--->NULL

Donate