Sunday, October 4, 2015

ASCII code of Alphabets in java

Write a java  Program that display ASCII code of  entered Character by user.

Program

import java.util.Scanner; // this package util and Class Scanner is declared to take input from user
/*
*@ scanner class
* @author khant vyas
*/
public class asciicode //asciicode is name of class
{

   public static void main(String args[])
     {

int x; // x is variable which stores value entered by user
Scanner sc= new Scanner(System.in);// sc is object to the Scanner class
System.out.println("Enter value you wan to see in ascii");
x=sc.nextInt();// nextInt() method is used accept intiger value from user
char c= (char) x ; // this conver character to ascii
System.out.println("ASCII code is "+c);


    }
}

Output:-
java ascii value of char image not displayed
Java Output

Saturday, October 3, 2015

Java Hello program.

              While writting a java program make sure you file name should be same as your Class name , and file name should be saved with extension .java
Java hello program is a basic program to represent to print Simple output in Java

Example
File name : Simpleprint.java
public class Simpleprint
{ //Simpleprint is name of class

public static void main(String args[])
{

 System.out.println("Hello Java");// this display output written in " "
                 System.out.println("Jai Shree krishna");

}



}

      To run Java file  open command prompt and first go to path of yor file then run .java file with command Javac after the type java and  class name in .java file and java code will excute
Output:
Java Hello image not found
output

Tuesday, March 8, 2011

Switch Case in C

The switch case is a good decision making statement in C language , as if statement has very much complexity in its structure and its difficult to handle multiple decision in with if..else .

  • The function of switch statement is to read the variable associated with it as (switch(variable)) and then it check the list of case , the value which matches ,with the case the function or statement associated with it is executed.

Structure of switch-case

variable;
switch (variable)
{
       case value-1:
      lines to be executed-1;
      break;
      case value-2:
      lines to be executed-1;
      break;
}

statements to be executed;


        Look friends in this above switch-case statements , the value-1 , value-2 are the title of the case
when any user type this title or value the corresponding lines associated with the case are executed respectively.
  • So remember friends when in above structure if you type value-1 then“lines to be executed-1;” this particular line will be executed and program will run further and it will return to “statements to be executed;” statement in program
  • Always remember that break function is necessary because if don,t use it your program will execute but suppose if you choose some value then all above values will be executed , and all line,s associated with it will be printed in program .

Example

#include<stdio.h>
#include<conio.h>
void main()
{
int day ; //day is variable which stores input integer value from user
clrscr();

printf("\nenter the number and u will know the day\n\n ");
scanf("%d",&day);

switch(day)
{
   case 1:
      printf("MONDAY");
   break;
   case 2:
      printf("TUESDAY");
   break;
   case 3:
      printf("WEDNESDAY");
   break;
   case 4:
      printf("THURSDAY");
   break;
   case 5:
      printf("FRIDAY");
   break;
   case 6:
      printf("SATURDAY");
   break;
   case 7:
      printf("SUNDAY");
   break;
}
getch();
}

Thursday, February 24, 2011

else if in c

Decision making is done by generally in four ways :
  1. By if statement
  2. switch statement
  3. conditional operator statement
  4. goto statement

if statement is good for decision making as it is very simple and it work on 2-ways decision (either this or that )
syntax
if(Test expression)

If the condition tested in if statement is true then it will execute the body of if statement or it will skip the body of if statement

Example
if (test expression )
{
       body part;
}

There are many types of if statements , depend on on which type of decision to be taken or what conditions are to be checked.

  • Simple if
  • if....else statement
  • Nested if …. else statement
  • else if ladder.
  • Simple if statement is given in the above example.


if....else statement

Structure of if...else

if  (test expression )
     {
         statement for true condition;
     }
else
    {
        statement for false condition;
    }
statements of program ;
While checking the test expression of if statement, for condition is true then if part is executed and for false condition else part is executed.

Nested if …. else statement

Structure of Nested if …. else

if(test expression-1 )
{
       if(test expression-2 )
          {
               statement for true condition;
          }
       else
          {
              statement for false condition;
          }
}
else
   {
         statement last;
   }
statements of program ;

When there are more condition to be checked and program is some what complicated this nested if..else structure is used.

  • Function of it is complicated. It will execute first “test expression-1” of if function , for true condition it will execute “test expression-2” of second if function , again condition is true then it will execute “statement for true condition;” and return “statements of program
  • suppose condition is false for “test expression-1”, then it will return else which contain“statement last;” ,and return “statements of program
  • suppose condition is false for “test expression-2”,and true for “test expression-1”,then it will return else which contain“statement for false condition;”,and return “statements of program









else if ladder

Structure of else if ladder

if(test expression-1 )
      statement-1;
else if(test expression-2 )
      statement-2;
else if(test expression-3 )
      statement-3;
else if(test expression-4 )
      statement-4;
else
      final statement;

statements of program ;

  • In else if ladder the condition are checked from top op to bottom in a sequence ,
  • As if condition is checked first and the followed by else if from top to bottom, if one condition is true,that statement is executed and program again returns to “statements of program ;
  • If all the condition are false the else is executed and final statement is executed as defolt statement
EXAMPLE
#include<stdio.h> // header files
#include<conio.h> //header files
void main()
{
  int marks ;
  clrscr(); //to clear output of previous program
  printf("\n\nenter your marks");
  printf("\n\n i will know grade and I m program\n\n ");
  scanf("\n\n%d",&marks);

  if(marks>=70)
   {
      printf("\n\nyou got distinsion");
   }
  else if(marks>=60)
  {
     printf("\n\nyou got first class");
  }
  else if(marks>=50)
  {
     printf("\nyou got second class");
  }
  else if(marks>=35)
  {
    printf("\nyou have just passed");
  }
  else
   printf("\nyou have failed");
   printf("\n\n\n");
   getch(); // It will accept one character from keyboard to end the program
}

I Hope friends  this may help you to understand the program easily post you suggesion and comments

Monday, February 21, 2011

Constants in C

             Constants refer to the values that are not changed during execution of program in C .There are two types of constants in C language basically :
  • Numeric constants
  • Character constants
Numeric constants are further divided in two parts real constants and Integer constants
Integer constant
An integer constant means the set of digits from 0 to 9 generally. Hexadecimal and octal integer are less in use in C programming .
  • Hexadecimal refer to digit 0 to 9 and alphabets from A to F where A means 10 and F means 15
  • Octal refer to the digit from 0 to 7 .

Example
#include<stdio.h>
#include<conio.h>

void main()
{
   clrscr();
   printf("This are integer\n");
   printf("%d\n %d\n",3456,-234);
   getch();
}

Output
This are integer
3456
-234




Real Constants
Numbers which are not possible to be representation in Integer form as they change there value or they have fraction part in them for e.g pi = 3.14 or any fraction number such as 15.45 which are in fraction part are known as real constants .
A real number can be executed in exponential form also and the general syntax is as follows
number e exponent
example 0.35e4 , 45e-5
The letter e separates the number from the exponents.
Character constants are are of two types single character constant and string constant .

Single character constant
A single character constant contain one character in a pair of single quote marks. e.g such as 'S' or '45'.

#include<stdio.h>
#include<conio.h>

void main()
{
   clrscr();
   printf("This are single character constant \n");
   printf("%c\n %d\n",'c','F');
   getch();
}

Output
This are single character constant
c
F
String Constant

  • A string constant is a sequence of character enclosed in double quotes. This character can be letter,number,special characters and blank space .

  • Example is seen in above program “This are single character constant” , this is a string with letters and blank space .
  • Backslash characters are also allowed in the string constants as “\n” is example of this type in the above program

C Tokens and Character set in C


  1. keywords
  2. Identifiers
  3. Constants
  4. String
  5. Special Character
  6. Operators




Keywords
  • In C keyword has a special meaning. It is special word of C which has predefined meaning .
  • there are 32 set of keywords in C Language
  • they are displayed by white colour in  turbo C 

Identifiers
  • It refer to the name of the variable ,function and array. they are user defined name ,consists of sequence of letter's , digits ,and upper case , lower case both type letters are allowed here .

Rules for Identifiers

1 First character must be an alphabet
2 Must contain only letters , digits or underscore
3 Only first 31 character are significant
4 Cannot use a key word
5 must not contain white space  

C constants




  • Constants means one whose value is not going to changed during the execution of whole program.
  • they are generally known as global declared variable
Strings
    • String is a sequence of character that is treated as single data item. When group of character is written in double quotation it is considered as string.
    • string can not be scan directly array of string has to be declared.
    Operators
    • Operator is a symbol that tells the compiler to perform the specific tasks.
    • they decide the priority of the operation to be performed .
    • There are eight type of operators in C language 
    The character in C are categories in four type
    1 letters
    2 digits
    3 special characters
    4 white space
    Compiler do not consider white space till they are not used in string constant







    Sunday, February 20, 2011

    LOOPS IN C LANGUAGE

    Why we use loops in C language or any language ? 

                 Look friends to understand the looping concept you need to know the importance of  loop , loops are use to perform any task repeatedly and take decision according to condition set in looping , loops are always a part of a big program . 

    Lopping in C
    Loops :- Loops generally possess two parts one is body of loop and another is called control statement .Control statement decides the category of loop,there for control statement is classified as entry-control loop or exit-control loop.
    Loops generally posses few steps :-
    • declaration and initialization of condition variable
    • writhing condition statement in loop
    • putting increment or changing condition of variable

    Loops provided by C language are as follows:-
    • While loop
    • Do loop
    • for loop
    While Loop
    format of while loop

    While (test condition )
    {
    Body of loop
    }

    example-

    int i=1 sum=0; /* initialization */
    While (i<=10 ) /* condition */
    {
    sum=i+1;
    i=i+1; /* increment */
    }

    Do Loop
    format of do loop:-

    do
    {
         Body of loop
    }
    While (test condition );
    note:- this will execute the loop 1st time and then from next time will check the condition of while till condition does not goes false .
    Example:-
    int I;
    do
    {
       printf(“Enter any number”)
       scanf(“%d”&i);
       printf(“number=%d”,i);
    }
    While (i>=1);

    For Loop:-
    for loop provides the best control structure and reduce the code length of a user.
    Format of for loop :-
    for (initialization;condition; increment)
    {
       body of loop;
    }

    example:-
    int I;
    for (i=1;i<=5; i++)
    {
         printf(“*”);
    }
    printf(“\n”);

    this will print 5 star in a column every star on new line .