Admin Welcomes U Simple Way to learn Java Programing in two Days ~ ANNA UNIVERSITY QUESTION BANKS PAPERS WITH SOLUTIONS

JOIN WITH US :)

If any add appear like this please click skip add

Category

INFO

CLICK HERE
FOR LATEST RESULTS
LATEST NEW TIME TABLE/EXAM DATES FOR ALL LINK1 LINK2
ANNA UNIVERSITY COLLEGES RANK LIST 2012 CHECK SOON
LATEST FREE PLACEMENT PAPERS FOR ALL COMPANIES CHECK SOON
GET FREE MINI PROJECTS AND FINAL YEAR PROJECTS CLICK HERE
LATEST HOT HACKING TRICKS CLICK HERE

LATEST QUESTION BANKS /PAPERS/entrance FOR ALL EXAMS CLICK HERE link1 link2




our sites
www.tricksnew.blogspot.com www.questionbank.tk
www.freeminiproject.blogspot.com and
www.onlineinfocity.
blogspot.com


NOTE:

FEEL FREE TO CONTACT US click on me
DONT FORGET TO SUBSCRIBE YOUR MAIL ID ----->>>TO GET DAILY question banks IN YOUR INBOX::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: SEE RIGHT SIDE CORNER

Wednesday, June 27, 2012

Simple Way to learn Java Programing in two Days

Simple Way to learn Java Programing in two Days JAVA PROGRAMING SIMPLE STEPS TO DEVELOP APLLICATIONS ND CODING



What is a CLASS & OBJECT? 

How do you differentiate these two ? Explain with examples.


                   A class is a template, blueprint, plan,design or protype from wichObjects can be derived
               If you create an object from a class , it means you created an instance of a class.
 

 A SMALL EXAMPLE IN MY VIEW.....

                               Suppose if you are planning to construct a house first step what you will do ?  you will go for design or plan of it, Once plan is ready you will start actual construction.    By keeping this plan with you,   construct  one more house ,like wise you can construct any number of houses.   Now here this plan is a class ,and actual construction is object. this class doesn't occupy any memory only object occupies memory.  From one class we can create ‘N’ number of objects.


Few points on Structured programming and Object oriented programming?


                   DESIGNER OF PASCAL LANGUAGE NIKLAUS WIRTH ONCE SAID
     "ALGORITHMS+DATASTRUCTURES=PROGRAMS".

HERE ALGORITHM COMES FIRST AND DATA STRUCTURES COMES SECOND.THIS IS HOW PROGRAMMERS  WERE  THINKING AT THAT TIME .FIRST THEY DECIDED THE PROCEDURES FOR MANIPULATIONS  OF DATA, THEN THEY DECIDED WHAT STRUCTURE TO IMPOSE ON DATA TO MAKE MANIPULATIONS EASIER.OOP  REVERSES THE ORDER AND PUTS DATA FIRST, THEN LOOKS AT THE ALGORITHM THAT OPERATE ON THE DATA. FOR SMALL PROGRAMS PROCEDURES WORKS WELL, BUT OBJECTS ARE BETTER FOR LARGER PROGRAMS. DEBUGGING ALSO EASIER  WITH  OOP.

Goals of JAVA!


When Java was invented it has few goals in mind,

1.       It should be simple
2.       It should be Object-Oriented
3.       It should be “robust and secure”
4.       It should be “platform independent and portable”
5.       It should execute with high performance
6.       It should be “interpreted, threaded and Dynamic”

What is JAVA ?

JAVA IS A PROGRAMMING LANGUAGE.

AS A WHOLE  JAVA IS A PLATFORM, WITH LARGE LIBRARY, CONTAINING LOTS OF REUSABLE CODE, AND AN EXECUTION ENVIRONMENT THAT PROVIDE SERVICES SUCH AS SECURITY, PORTABILITY ACROSS SYSTEMS AND AUTOMATIC GARBAGE COLLECTION.

JAVA IS A HIGH QUALITY ENVIRONMENT AND LIBRARY.



History of JAVA


                       Actually Java was originally designed for programming consumer devices, but it was first succeful ly used to with internet applets.In the year 1991, when a group of SUN  engineers (which is now subsidiary  of oracle corporation) led by James Gosling,  Patrick Nauton, Mile Sheridon  wanted to design a small computer language that could be used for    consumer devices like, cable TV switch boxes, remote controller, Microwave oven. Because these devices do not have lot of memory the language had to be small and generate very tight code. Also, because different manufacturers may choose different CPUs, it was important that the language not be tied to as single architecture, the project was code-named “Green”.
Later it renamed as “OAK” after an oak tree that stood outside gosling’s office. Then it renamed as JAVA.

Versions history you can find in the wiki:-


When API was growing it because difficult for SUN to Maintain. 


They divided it in to 3 parts
1. J2SE            2.J2EE               3.J2ME
and now it is called
 1.JSE             2.JEE                 3.JME

What is Programming?


                                   NOW A DAY COMPUTERS BECAME PART OF HUMAN LIFE .MANY PEOPLE USES IT FOR DIFFERENT PURPOSES LIKE PLAYING GAMES, BANKING TRANSACTIONS, AND FOR ONLINE PURCHASES. THESE COMPUTERS HAS NO INTELLIGENCE BY ITSELF, IT SIMPLY EXECUTES INSTRUCTIONS THAT HAVE BEEN PREPARED IN ADVANCE. IN ORDER TO ACHIEVE THIS FLEXIBILITY THE COMPUTERS MUST BE PROGRAMMED TO PERFORM EACH TASK, DIFFERENT TASKS REQUIRE DIFFERENT PROGRAMS. THESE PROGRAMS ARE SEQUENCE OF INSTRUCTIONS AND DECISION THAT COMPUTERS CARRYOUT TO ACHIEVE A TASK.  THE ART OF WRITING THESE KINDS OF PROGRAMS IS NOTHING BUT PROGRAMMING.   

Simple Way to learn Java Programing in two Days

STRINGS BASIC PROGRAM SERIES-1

PROGRAM TO WRITE A REVERSE OF A STRING:-

package com.javainchennai;
import java.util.Scanner;
public class StringReverse {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter a String");
        String str=sc.nextLine();
        int strLen=str.length();
        char c[]=new char[20];
        
        for(int i=0,j=strLen-1;i<strLen;i++,j--)
        {
            c[i]=str.charAt(j);
            System.out.print(c[i]);
        }    
    }
}
OUTPUT:-
Enter a String
madam123
321madam
STRING PALINDROME PROGRAM
package com.javainchennai;
import java.util.Scanner;
public class Stringpolindrome {
    public static void main(String[] args) {
    
    int i,j=0;
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter your String:-");
    String str=sc.next();
    char c[]=new char[20];
    c=str.toCharArray();
    i=str.length();
    --i;
    while(j<=i)
    {
        if(c[i]!=c[j])
        {
            System.out.println("The given string "+ str +" is not polindrome");
            System.exit(0);    
        }
        ++j;
        --i;
        
    }
    System.out.println("The given string" + str +"is polindrome");
    }
}
OUTPUT-1 :
Enter your String:-
javainchennai
The given string javainchennai is not polindrome
OUTPUT-2 :
Enter your String:-
malayalam
The given string  malayalam is polindrome

FINDING THE LENGTH OF A STRING

package com.javainchennai;
import java.util.Scanner;
public class StringLength {
    public static void main(String[] args) {
     Scanner sc=new Scanner(System.in);
     System.out.println("Please Enter your String:-");
     String str=sc.nextLine();
     char c[]=new char[10];
     
      c= str.toCharArray();
    int count=0;
    try{
     for( count=0;c[count] !='\0'; count++);
    }
     catch (ArrayIndexOutOfBoundsException e) {
       System.out.println(count);
     } 
      
    }
}
Please Enter your String:-
questionabanks
The Length of the Given String is: 13

FINDING THE NUMBER OF WORDS IN A STRING

package com.javainchennai;
import java.util.Scanner;
public class NoOfWordsInAString {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter your string:-");
        String str=sc.nextLine();
        int strLen=str.length();
        int word=1;
        for(int i=0;i<strLen-1;i++)
        {
            if((str.charAt(i))==' ')
            {
                word++;
            }    
        }
        System.out.print("The Number of words in the Given String are :" +word);
    }
}
OUTPUT:-
Enter your string:-
question banks
The Number of words in the Given String are :2

--------------------------------------------------------------------------------------------------------------

Before going into programs a small introduction on Strings

If there is any mistakes in this article please write me  blog4helping@gmail.com
======================
               -:STRINGS:-
======================
1.String is a class in Java
2.String means collection of characters
3.String is a sequence of characters enclosed in double Quotes.
4.Java Strings are sequence of Unicode characters 
5.String class produces Immutable objects.
6.String class does not have a methods that let you change a characters in an existing String.
7.It is like number 5 , the String "HELLO" we cannot change it.
    
Sting Objects can be created in 2 ways
       
           1. without using new operator
                         String str1="javainchennai";
       
           2. with using new operator 
                         String str2=new String("javainchennai");
                
  
The memory space is divided in to 2 parts 
                      1.constant area
                      2.non-constant area        
   
If you create object without using new operator this will be saved in constant area
                       String str1="javainchennai";
                  
If you create object with using new operator this will be saved in non-constant area
                        
                      String str2=new String("javainchennai");
Here Constant area will not allow duplicates
 where as non-constant area will allow duplicates. 
Do Remember inside a String class the toString() method is  overided 
   
    Here if you try to print reference variable
         
         String s1="javainchennai";
         System.out.println(s1);
         The output is javainchennai   instead of String@ff2201(classname @ hexadecimal value)
equals() method also overrided to check 2 objects based on the value(content) it contains
   
observe the program carefully and read the explanation:-
1.package com.qb;
2.public class StringTest {
3.    public static void main(String[] args) {
4.        String str1="javainchennai";
5.        String str2="javainchennai";
6.        String str3=new String("javainchennai");
7.        String str4=new String("javainchennai");
8.        System.out.println(str1==str2);
9.        System.out.println(str1==str3);
10.        System.out.println(str2==str3);
11.        System.out.println(str3==str4);
12.        System.out.println(str1.equals(str2));
13.        System.out.println(str1.equals(str3));
14.        System.out.println(str2.equals(str3));
15.        System.out.println(str3.equals(str4));
16.    }
17.   }
output:-
true
false
false
false
true
true
true
true
explanation:-
If you say 5==5 is true, here two are primitive literals so == operator(checks content) prints true.
If you use == operator to compare two object references it will see whether both references are pointing to same object or different.
If both references are pointing to same object it(== operator) returns true otherwise false.
observe line4 and line5 ,here actually I created String object without using new operator so, str1 and str2 both references are pointing to same object (javainchennai). (constant area will not allow duplicates)
so, str1==str2 returns true.
observe line4 and line5 ,here actually I created String object by using new operator so, str3 and str4 both references are pointing to different objects (javainchennai).(non constant area allows duplicates). 
So, str3==str4 returns false.
Observe the same effect with equals() method it returns true all time .(because it is overrided to compare based on content inside object)
PROGRAMS:-
program:-
1.public class StringTest {
2.    public static void main(String[] args) {
3.                            System.out.println(3+5);
4.                            System.out.println("3"+5);
5.                            System.out.println(3+"555");
6.                            System.out.println(3+2+5+"4444");
7.                            System.out.println("35"+111+"99");
8.                            System.out.println("42"+11+32+"77");
9.                            System.out.println("100"+"222");
   }
}
OUTPUT:-
8
35
3555
104444
3511199
42113277
100222
Explanation:-
-------------
In Java there is no operator overloading concept.
+ is the only one operator overloaded to add 2 integers as well as 2 strings
In the above example we added 2 primitives that is common ,
when we added String with any primitives only String object is produced.
observe the output of lines 6,7,8,9.

DIFFERENCES BETWEEN STRING , STRINGBUFFER AND STRINGBUILDER


String:-

------------------
1.String class introduced in jdk1.0
2.String class is a final class and implements Serializable,Comparable and CharSequence interfaces
3.String Objects can be created in two ways     a.Using new operator
constructors to create String ob
    b.Without using new operator 4.----- 5. String class has several jects(both using new or without using new operator)      a.String s1="";      
that it represents an empty char
     b.String s2=new String("");                Initializes a  String object so acter sequence.      c.String s1="javainchenna";

resents the same sequence of characters as the argument    
     5.String class has no append method.
6.There
        Initializes a  String object so that it re p is no delete method to delete a characters from . 7.StringBuilder objects are Non-Synchronized. ------------------
StringBuffer:-    
------------------
StringBuffer and StringBuilder has the same methods:-
1.String class introduced in jdk1.0

lements Serializable and CharSequence interfaces


.StringBuffer Objects cannot  be cre
3
2.String class is a final class and im pated without using  new operator      StringBuffer s2="javainchennai";(wrong way)        

ffer("");


         Constructs a StringBuffer with no
4.use new operator to create objects of StringBuffer          StringBuffer sb1=new StringB u characters in it and an initial capacity of 16 characters.

g representation of the any type(primitive or derived) argument to the sequence.


.There is a delete method  to delete a characters from this
6
5.StringBuffer class has append() method , It appends the stri nobject. 7.StringBuffer objects are Synchronized.StringBuffer was being used by a single thread. ------------------
StringBuilder:-
------------------
.String class introduced in jdk1.5
1,

tring class is a final class and implements Serializable and CharSequence interfaces

3
2. S.StringBuffer Objects cannot  be created without using  new operator

or to create objects of StringBuilder


         Strin
        StringBuilder s3="javainchennai";(wrong way) 4.use new opera tgBuilder sb1=new StringBuilder();   

th no characters in it and an initial capacity of 16 characters.
    

ngBuilder class has appen
5.Str i
         Constructs a StringBuilder w id() method,It appends the string representation of the any type(primitive or derived) argument to the sequence.
d.
6. There is a delete method  to delete a characters from this object. 7.StringBuilder objects are Non-Synchroniz
e

--------------------------------------------------------------------------------------------------------------

FIND BIGGEST OF 3 NUMBERS:

import java.util.Scanner;
public class biggest
 {
            public static void main(String[] args)
{
                        System.out.println("Enter 3 numbers");
                        Scanner sc=new Scanner(System.in);
                        int a=sc.nextInt();
                        int b=sc.nextInt();
                        int c=sc.nextInt();
                        int max=a;
                        if(b>max)
                                    max=b;
                        if(c>max)
                                    max=c;
                        System.out.println("The biggest of 3 numbers:"+max);
                        }
}
Output:
Enter 3 numbers
65
98
43
The biggest of 3 numbers:98

FIND GIVEN NUMBER IS ODD OR  EVEN:

import java.util.Scanner;
public class evenodd
{
            public static void main(String[] args)
{
                        System.out.println("Enter the number");
                        Scanner sc=new Scanner(System.in);
                        int num=sc.nextInt();
                        if(num/2==1)
                                                System.out.println("Number is ODD");
                        else
                                    System.out.println("Number is EVEN");
                                    }
}
Output:
Enter the number
88
Number is EVEN

FIND GIVEN NUMBER IN PERFECT SQUARE OR NOT:

import java.util.Scanner;
public class perfectsquare
{
            public static void main(String[] args)
{
                        System.out.println("Enter a number");
                        Scanner sc=new Scanner(System.in);
                        int num=sc.nextInt();
                        double num1=Math.sqrt(num);
                        double num2=num1;
                        if(num1==num2)
                                    System.out.println(num + "is a perfect square");
                        else
                                    System.out.println(num + "is not a perfect square");
            }
}
Output:
Enter a number
100
100is a perfect square

WRITE A PROGRAM TO FIND GIVEN NUMBER IS PALINDROME OR NOT

import java.util.Scanner;
public class PalindromeOfNumber
{
            public static void main (String[] args)
 {
                         int mod=0;
                         int c=0;
                         int d=0;
                         int num1=0;
                         System.out.println("Enter a number:");
                                    Scanner sc=new Scanner(System.in);
                                     int num=sc.nextInt();
                                    num1=num;
           while(num>0)
           {
               mod=num%10;
               c=c+mod;
               num=num/10;
               d=mod+d*10;
                          }
           if(num1==d)
           {   System.out.println("The given number "+num1+" is palindrome");
           }
           else
           {
               System.out.println("The given number "+num1+" is not palindrome");
           }
            }
}
OUTPUT:
RUN 1:
Enter a number:
1523
The given number 1523 is not palindrome

WRITE A PROGRAM TO FIND GIVEN NUMBER IS PRIME OR NOT

import java.util.Scanner;
public class PrimeOrNot
{
            public static void main(String[] args)
{
    System.out.println("Enter the number:");
     Scanner sc=new Scanner(System.in);
     int i;
     int flag=0;
     long num=sc.nextLong();
     if(num<=3)
             System.out.println("The given number is prime:");
     else
              for(i=2;i<=num/2;i++)
                          if(num%i==0)
                          {
                                      flag=1;
                                      break;
                          }
                          else
                                      flag=0;
     if(flag==1)
             System.out.println("The given number "+num+"  is not prime");
     else
             System.out.println("The given number "+num+" is prime");
                        }
}
Output1:
Enter the number:
5
The given number 5 is prime
Output2:
Enter the number:
55
The given number 55  is not prime

WRITE A PROGRAM TO DISPLAY MULTIPLICATION TABLE

import java.util.Scanner;
public class multiplicationtable
{
            public static void main(String[] args)
{
                        System.out.println("Enter the table number and the count value:");
                        Scanner sc=new Scanner(System.in);
                        int tnum=sc.nextInt();
                        int count=sc.nextInt();
                        System.out.println("The table is ...");
                        for(int i=1;i<=count;i++){
                        System.out.println(tnum+"*"+i+"=" + i*tnum);
                        }
            }
}
Output:
Enter the table number and the count value:
8
10
The table is ...
8*1=8
8*2=16
8*3=24
8*4=32
8*5=40
8*6=48
8*7=56
8*8=64
8*9=72
8*10=80

WRITE A PROGRAM TO FIND COMMAND LINE NUMBER COUNT

public class CommandLineNumbersCount
 {
            public static void main(String[] args)
{
                  int l=args.length;
         System.out.println(l);
            }
 }
OUT PUT:
Java CommandLineNumbersCount 10 5 23 4 2
                5
            java CommandLineNumbersCount 21 3 36 4
               4

WRITE A PROGRAM TO SORT THE DIGITS OF A NUMBER IN ASCENDING ORDER

import java.util.Scanner;
public class SortDigitsInInteger
{
            public static void main(String[] args)
{
                        Scanner sc=new Scanner(System.in);
                        System.out.println("Enter a number:-");
                        int num=sc.nextInt();
                        int a,i=0;
                        int sort[]=new int[10];
                while(num>0)
                {
                 a=num%10;
                 sort[i]=a;
                 i++;
                 num=num/10;
                }
                for(int j=0;j<i-1;j++)
                 for(int k=j+1;k<i;k++)
                 if(sort[j]>sort[k])
                 {
                         int temp=sort[j];
                         sort[j]=sort[k];
                         sort[k]=temp;
                 }
                System.out.println("The digits in number ascending order:");
                for(int j=0;j<i;j++)
                        System.out.print(sort[j]+" ");
            }
}
OUTPUT:
Enter a number:-
4261
The digits in number ascending order:
1 2 4 6

WRITE A PROGRAM TO SORT A NUMBER IN ASCENDING ORDER

import java.util.Scanner;
public class SortNumbersInAscendingOrder
{
            public static void main(String[] args)
{
                        Scanner sc=new Scanner(System.in);
                        System.out.println("Enter Number of elements:-");
                            int limit=sc.nextInt();
                            System.out.println(" Enter Elements:- ");
                            int a[]=new int[10];
                            for(int  i=1;i<=limit;i++)
                            {  
                               a[i]=sc.nextInt();
                            }
                             for(int  i=0;i<limit-1;i++)
                                    for(int j=i;j<limit;j++)
                                                            if(a[i]>a[j])
                                                            {
                                                int        temp=a[i];
                                                            a[i]=a[j];
                                                            a[j]=temp;
                                  }
       System.out.println("The sorted list is:-");
        for( int i=0;i<limit;i++)
                      System.out.print("   "+a[i]);
            }
}
OUTPUT:
Enter Number of elements:-
5
 Enter Elements:-
15 25 16 12 4
The sorted list is:- 
  0   12   15   16   25

-------------------------------------------------------------------------------------------------

PROGRAMMING WITH RECURSION  

 Fibonacci series

import java.util.Scanner;
public class FibonacciSeries
{
            public static void main(String[] args)
            {
                        int x=0,y=1;
                        Scanner sc=new Scanner(System.in);            
                        System.out.println("Enter a Number:-");    
                int z=sc.nextInt();
                System.out.println("The fibo series is:- ");
                fiboSeries(z,x,y);
            }
            private static void fiboSeries(int x,int f,int f1)
            {
                        if(x==0)
                            System.exit(0);
                        System.out.print("  " + (f+f1));
                        fiboSeries(--x,f1,f+f1);
            }
}
OUTPUT
Enter a Number:-
8
The fibo series is:-
  1  2  3  5  8  13  21  34
Enter a Number:-
10
The fibo series is:-
  1  2  3  5  8  13  21  34  55  89
  

Tribonacci series 

mport java.util.Scanner; 
i

ublic class TribonacciSeries
p

{
            public static void main(String[] args)
            {
                        int x=-1,y=1,z=0;
                        Scanner sc=new Scanner(System.in);            
                        System.out.println("Enter a Number:-");    
                int n=sc.nextInt();
                System.out.println("The tribo series is:- ");
                triboSeries(n,z,x,y);
            }
            private static void triboSeries(int x,int f,int f1,int f2)
            {
                        if(x==0)
                            System.exit(0);
                        System.out.print("  " + (f+f1+f2));
                        triboSeries(--x,f1,f2,f+f1+f2);
            }
}
OUTPUT
Enter a Number:-
10
The tribo series is:-
  0  0  1  1  2  4  7  13  24  44
Enter a Number:-
8
The tribo series is:-
  0  0  1  1  2  4  7  13
 WRITE A PROGRAM TO FIND THE POWER OF THE NUMBER
import java.util.Scanner;
public class XpowN
{
            public static void main(String[] args)
{
                       
            Scanner sc=new Scanner(System.in);
            System.out.println("Enter the values of X and N:-");
            double x=sc.nextDouble();
            int n=sc.nextInt();
            System.out.println(power(x,n));         
            }
            private static double power(double x,int n)
            {
                        double pow=0;
                         pow= ((n==0)?1:x*power(x,n-1));
                       
                        return pow;
            }
}
OUTPUT
Enter the values of X and N:-
10
5
100000.0
Enter the values of X and N:-
5 2
25.0

--------------------------------------------------------------------------------------------------------------

PROGRAM TO READ AN INTEGER AND REDUCE IT TO A SINGLE DIGIT

import java.util.Scanner;
public class DigitReduce
 {
            public static void main(String[] args)
{
                        Scanner sc=new Scanner(System.in);
                        System.out.println("Enter a Number:-");    
                long num=sc.nextLong();
                System.out.println(" " + calculateDigit(num));
            }
            private static long calculateDigit(long num)
{
                       
                        return (num/10 == 0 ? num : calculateDigit(num/10 + num % 10));
            }
}
OUTPUT
Enter a Number:-
4789
 1
Enter a Number:-
3348
 9

WRITE A PROGRAM TO DISPLAY AMOUNT INTO 500’S,100’S,50’S,20’S,10’S,5’S,2’S,1’S IN A GIVEN NUMBER

import java.util.Scanner;
public class AmountCount
{
      public static void main(String[] args)
{
              System.out.println("Enter the amount in rupees:-");
              Scanner sc=new Scanner(System.in);
              int num=sc.nextInt();
              while(num>=500)
              {
                        int a=num/500;
                        System.out.print("\n The no .of five hundreds are:- "+ a);
                        break;
              }
              while(num>=100){
                          int a=num/100;
                        System.out.print("\n The no .of hundreds are :-"+ a);
                        break;
              }
              while(num>=50){
                          int a=num/50;
                        System.out.print("\n The no .of fiftie's are "+ a);
                        break; 
              }
              while(num>=20)
              {
                           int a=num/20;
                           System.out.print("\n The no .of twenty's are "+ a);
                           break;
              }
              while(num>=10){
                          int a=num/10;
                        System.out.print("\n The no .of ten's are "+ a);
                        break;
              }
              while(num>=5){
                          int a=num/5;
                        System.out.print("\n The no .of five's are "+ a);
                        break; 
              }
              while(num>=2){
                          int a=num/2;
                        System.out.print("\n The no .of two's are "+ a);
                        break;
           
  }
              while(num>=1)
              {
                          int a=num/1;
                        System.out.print("\n The no.of one's are"+ a);
                        break;
              }
              }
            }
OUTPUT:
Enter the amount in rupees:-
1854
 The no .of five hundreds are 3
 The no .of hundreds are 18
 The no .of fiftie's are 37
 The no .of twenty's are 92
 The no .of ten's are 185
 The no .of five's are 370
 The no .of two's are 927
 The no.of one's are1854

WRITE A PROGRAM TO SORT A NUMBER IN ASCENDING ORDER

import java.util.Scanner;
public class SortNumbersInAscendingOrder
{
            public static void main(String[] args)
{
                        Scanner sc=new Scanner(System.in);
                        System.out.println("Enter Number of elements:-");
                            int limit=sc.nextInt();
                            System.out.println(" Enter Elements:- ");
                            int a[]=new int[10];
                            for(int  i=1;i<=limit;i++)
                            {  
                               a[i]=sc.nextInt();
                            }
                             for(int  i=0;i<limit-1;i++)
                                    for(int j=i;j<limit;j++)
                                                            if(a[i]>a[j])
                                                            {
                                                int        temp=a[i];
                                                            a[i]=a[j];
                                                            a[j]=temp;
                                  }
       System.out.println("The sorted list is:-");
        for( int i=0;i<limit;i++)
                      System.out.print("   "+a[i]);
            }
}
OUTPUT:
Enter Number of elements:-
5
 Enter Elements:-
15 25 16 12 4
The sorted list is:-
   0   12   15   16   25

--------------------------------------------------------------------------------------------------------------

WRITE A PROGRAM TO CONVERT INTEGER INTO IT’S EQUIVALENT NAME

import java.util.Scanner;
public class IntegerToItsEqualentName
{
            public static void main(String[] args)
{
                        Scanner sc=new Scanner(System.in);
                        System.out.println("Enter Number");
                 int num=sc.nextInt();
                 int m=0,c=0;
                 int a[]=new int[10];
                 while(num>0)
{
                         m=num%10;
                         a[c]=m;
                         num=num/10;
                         c++;
                 }
                for(int k=c-1;k>=0;k--)
{
                switch (a[k])
{
                case 0:System.out.print("ZERO ");
        break;
                        case 1:System.out.print("ONE ");
                                       break;
                case 2:System.out.print("TWO ");
                        break;
                case 3:System.out.print("THREE ");
                        break;
                case 4:System.out.print("FOUR ");
                        break;
                case 5:System.out.print("FIVE ");
                        break;
                case 6:System.out.print("SIX ");
                          break;
                case 7:System.out.print("SEVEN ");
                        break;
                case 8:System.out.print("EIGHT ");
                         break;
                case 9:System.out.print("NINE ");
                    
    break;
                        default:
                                    break;
                        }
}
                
            }
}
OUTPUT:
Enter Number
12069
ONE TWO ZERO SIX NINE

PROGRAM FOR SWAPPING TWO NUMBERS USING THREE VARIABLES

import java.util.Scanner;
public class Output
{
            public static void main(String[] args)
{
                        System.out.println ("enter 2 numbers");
                        Scanner sc=new Scanner(System. in);
                        int num1 =sc.nextInt();
                        int num2 =sc.nextInt();
                        System.out.println("Before swapping");
                        System.out.println("num1:"+num1+"\n"+"num2:"+num2);
                        int temp=num1;
                           num1=num2;
                           num2=temp;
        System.out.println("After swapping");
        System.out.println("num1:"+num1+"\n"+"num2:"+num2);
            }
}
Output:
enter 2 numbers
55
65
Before swapping
num1:55
num2:65
After swapping
num1:65
num2:55

PROGRAM FOR SWAPPING TWO NUMBERS WITHOUT USING THIRD VARIABLE

import java.util.Scanner;
public class swapping2
 {
public static void main(String args[])
            {                                                                                  
              System.out.println("Enter 2 numbers");
              Scanner sc=new Scanner(System.in);
              int num1=sc.nextInt();
              int num2=sc.nextInt();
              System.out.println("Before swapping");
              System.out.println("num1:"+num1+"\n"+"num2:"+num2);
                 num1=num1+num2;
                 num2=num1-num2;
                 num1=num1-num2;
              System.out.println("After swapping");
              System.out.println("num1:"+num1+"\n"+"num2:"+num2);
                          }
}
Output:
Enter 2 numbers
23
32
Before swapping
num1:23
num2:32
After swapping
num1:32
num2:23
   

SWAPPING 2 NUMBERS WITHOUT USING ARITHMETIC OPERATORS

import java.util.Scanner;
public class arithmatic
 {
            public static void main(String[] args)
{
            System.out.println("Enter 2 numbers");
            Scanner sc=new Scanner(System.in);
              int num1=sc.nextInt();
              int num2=sc.nextInt();
              System.out.println("Before swapping");
              System.out.println("num1:"+num1+"\n"+"num2:"+num2);
                 num1=num1^num2;
                 num2=num1^num2;
                 num1=num1^num2;
              System.out.println("After swapping");
              System.out.println("num1:"+num1+"\n"+"num2:"+num2);
            }
}
Output:
Enter 2 numbers
19
91
Before swapping
num1:19
num2:91
After swapping
num1:91
num2:19

--------------------------------------------------------------------------------------------------------------

        WHETHER IT IS C , C++, C# OR JAVA , WORKING WITH THESE KIND OF PROGRAMS GIVES YOU LOT OF  FUN :-
   

Write a program to display the following output

  
2  2 
3  3  3 
4  4  4  4 
5  5  5  5  5 
import java.util.Scanner;
public class ForLoop1
{
            public static void main(String[] args)
               {
                           System.out.println("Enter the limit:-");
                           Scanner sc=new Scanner(System.in);
                           int limit=sc.nextInt();
                            for(int i=1;i<=limit;i++)
                                {
                                     for(int j=1;j<=i;j++)
                                        {
                                          System.out.print( i +"  ");
                                          }
                                         System.out.println();
                               }
                  }
}
Enter the limit:-
5
2  2 
3  3  3 
4  4  4  4 
5  5  5  5  5 

Write a program to display the following output 

1  2 
1  2  3 
1  2  3  4 
1  2  3  4  5 
package com.vel.nestedforloop;
import java.util.Scanner;
public class ForLoop2
{
            public static void main(String[] args)
              {
                             System.out.println("Enter the limit:-");
                            Scanner sc=new Scanner(System.in);
                               int limit=sc.nextInt();
                              for(int i=1;i<=limit;i++)
                               {
                                 for(int j=1;j<=i;j++)
                                    {
                                      System.out.print( j +"  ");
                                     }
                                 System.out.println();
                               }
        }
}
Enter the limit:-
5
                                                                        1  
                                                                        1  2  
                                                                            1  2  3 
                                                                                     1  2  3  4  
                                                                                      1  2  3  4  5

Write a program to display the following output

2  3 
4  5  6 
7  8  9  10 
11  12  13  14  15 
16  17  18  19  20  21 
package com.vel.nestedforloop;
import java.util.Scanner;
public class ForLoop3
{
            public static void main(String[] args)
{
                           System.out.println("Enter the limit:-");
                           Scanner sc=new Scanner(System.in);
           int limit=sc.nextInt();
           int k=1;
           for(int i=1;i<=limit+1;i++)
{
               for(int j=1;j<=i;j++)
{
                           System.out.print( k++ +"  ");
               }
               System.out.println();
           }
            }
}
Enter the limit:-
5
2  3 
4  5  6 
7  8  9  10 
11  12  13  14  15 
16  17  18  19  20  21 

WRITE A PROGRAM TO DISPLAY THE FOLLOWING OUTPUT
 

3 2 1 0 1 2 3 
import java.util.Scanner;
public class LineFormat
{
            public static void main(String[] args)
{
                        int i,j,k;
                        System.out.println("Enter Limit:-");
                        Scanner sc= new Scanner(System.in);
                        int n=sc.nextInt();
                        k=n;
                        for(i=0;n>=i;i++,k--)
                                    System.out.print(" "+k);
                        k=1;
                        for(j=0;j<n;j++,k++)
                                    System.out.print(" "+k);
            }
}
OUTPUT
Enter Limit:-
3
 3 2 1 0 1 2 3

Write a program to display the following output

  
  
 1
 1    1
 1    1    1
import java.util.Scanner;
public class NumberGenerator
{
public static void main(String[] args)
{
            int i,j;
            System.out.println("ENTER THE NUMBER TO BE DISPLAYED :-");
            Scanner sc=new Scanner(System.in);
            int a=sc.nextInt();
            System.out.println("ENTER THE SIZE :-");
            int n=sc.nextInt();
            for(i=0;i<n;i++)
            {
                        for(j=0;j<=i;j++)
                        System.out.print(" "+a);
                        System.out.println();
            }         
}
}
ENTER THE NUMBER TO BE DISPLAYED :-
1
ENTER THE SIZE :-
3
 1
 1    1
 1    1    1

  

WRITE A PROGRAM TO DISPLAY THE FOLLOWING OUTPUT

ENTER THE LIMIT:-
6
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
import java.util.Scanner;
public class GenerateNumber1
{
            public static void main(String[] args)
{
                        int i,j;
                        System.out.println( "ENTER THE LIMIT:-");
                        Scanner sc=new Scanner(System.in);
                        int n=sc.nextInt();
                        for(i=1;i<n;i++)
                        {
                                    for(j=i;j>0;j--)
                                    {
                                                System.out.print(j+" ");
                                    }
                                    System.out.println();
                        }
            }
}
OUTPUT
ENTER THE LIMIT:-
6
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1

Write a program to print the following output

1  0  0  0
0  2  0  0
0  0  3  0
0  0  0  4
import java.util.Scanner;
public class GenerateNumber1
{
            public static void main(String[] args)
{
                        int i,j,x=0;
                        System.out.println( "ENTER THE LIMIT:-");
                        Scanner sc=new Scanner(System.in);
                        int n=sc.nextInt();
                        for(i=1;i<=n;i++)
                        {
                                    for(j=1;j<=n;j++)
                                    {
                                                if(i==j)
                                                   System.out.print(i+" ");
                                                else
                                                            System.out.print(x +" ");
                                    }
                                    System.out.println();
                        }
            }
}

Write a program to print the following output with the given character

ENTER THE CHARACTER TO BE DISPLAYED:-
7
ENTER THE LIMIT:-
4
7 7 7 7
7 7 7 7
7 7 7 7
7 7 7 7
import java.util.Scanner;
public class GenerateNumber1
{
            public static void main(String[] args)
{
                        int i,j,x=0;
                        Scanner sc=new Scanner(System.in);
                        System.out.println("ENTER THE CHARACTER TO BE DISPLAYED:-");
                   int  c=sc.nextInt();
                        System.out.println( "ENTER THE LIMIT:-");
                        int n=sc.nextInt();
                       
                        for(i=1;i<=n;i++)
                        {
                                    for(j=1;j<=n;j++)
                                    {
                                                   System.out.print(c+" ");
                                    }
                                    System.out.println();
                        }
            }
}

.Write a program to print the following output with the given character

ENTER THE CHARACTER TO BE DISPLAYED:-
8
ENTER THE LIMIT:-
4
8 8 8 8
8       8
8       8
8 8 8 8
import java.util.Scanner;
public class GenerateNumber1
{
            public static void main(String[] args)
{
                        int i,j,x=0;
                        Scanner sc=new Scanner(System.in);
                        System.out.println("ENTER THE CHARACTER TO BE DISPLAYED:-");
                   int  c=sc.nextInt();
                        System.out.println( "ENTER THE LIMIT:-");
                        int n=sc.nextInt();
                       
                        for(i=1;i<=n;i++)
                        {
                                    for(j=1;j<=n;j++)
                                    {   
                                          if(i==1||j==1||j==n||i==n)  
                                                   System.out.print(c+" ");
                                          else
                                                  System.out.print("  ");
                                    }
                                    System.out.println();
                        }
            }
}

Program to read an integer and reduce it to a single digit

import java.util.Scanner;
public class DigitReduce
 {
            public static void main(String[] args)
{
                        Scanner sc=new Scanner(System.in);
                        System.out.println("Enter a Number:-");    
                long num=sc.nextLong();
                System.out.println(" " + calculateDigit(num));
            }
            private static long calculateDigit(long num)
{
                       
                        return (num/10 == 0 ? num : calculateDigit(num/10 + num % 10));
            }
}
OUTPUT
Enter a Number:-
4789
 1
Enter a Number:-
3348
 9

1 comments:

Reetha said...

Dear All

If there is any error in above program or wanna download full article please request us via sms or contact form :)

Wish you All the best friends and professors

chitika