write a program to print- improv

Upload: angel-ayushi

Post on 07-Apr-2018

230 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/6/2019 Write a Program to Print- IMPROV

    1/32

    JAVA PROJECT FILE (X)

    Write a program find the charge of Phone bill according to given tariff

    Unit Cost/unit

    200 1.50

    import java.io.*;

    class charge

    {

    public static void main(String[] args)

    {int d;

    BufferedReader ob= new BufferedReader (new InputStreamRaeder(System.in));

    string x=ob.readLine();

    u= Integer.parseInt(x);

    if (u100&&u200)

    float charge = (100*0.80+10*1+(u-200)*1.50);

    System.out.println(+charge);}

    }

    Input :- 50

    Output :- 40

    Variable Description :

    u int take the input from user

    charge float store the total charge

    STEP -1 WRITE THE CLASS NAME

    STEP -2 WRITE THE MAIN IN THE PROGRAM

    STEP -3 TAKES THE VALUE FROM THE USER

    STEP -4 CALCULATE THE CHARGES

    STEP -5 PRINT THE CHARGES

    1

  • 8/6/2019 Write a Program to Print- IMPROV

    2/32

    JAVA PROJECT FILE (X)

    Write a Program to print

    1

    12

    123

    1234

    STEP -1 WRITE THE CLASS NAME

    STEP -2 WRITE THE MAIN IN THE PROGRAM

    STEP -3 FOR LOOP I1 TO 4STEP -4 FOR LOOP J1 TO ISTEP 5 PRINT THE J

    class Peramid

    {

    public static void main(String[] args)

    {

    for(int i=1;i

  • 8/6/2019 Write a Program to Print- IMPROV

    3/32

    JAVA PROJECT FILE (X)

    Write a Program to print

    55555

    4444

    333

    22

    1

    STEP -1 WRITE THE CLASS NAME

    STEP -2 WRITE THE MAIN IN THE PROGRAMSTEP -3 FOR LOOP I5 TO 1STEP -4 FOR LOOP J1 TO ISTEP 5 PRINT THE I

    class Peramid

    {

    public static void main(String[] args)

    {

    for(int i=5;i>=1;i--)

    {

    for(int j=5;j

  • 8/6/2019 Write a Program to Print- IMPROV

    4/32

    JAVA PROJECT FILE (X)j int use in inner for loop

    Write a program to print all prime number between 1 to 20

    STEP -1 WRITE THE CLASS NAME

    STEP -2 WRITE THE MAIN IN THE PROGRAM

    STEP -3 FOR LOOP N1 TO 20STEP -4 C 0STEP -5 FOR LOOP I1 TO NSTEP -6 IF C=2

    STEP 7 PRINT THE N

    import java.io.*;

    class Prime

    {

    public static void main(String args[])

    {

    int n ;

    for (n=1;n

  • 8/6/2019 Write a Program to Print- IMPROV

    5/32

    JAVA PROJECT FILE (X)

    Variable Description :

    n int use in outer for loop

    i int use in inner for loop

    c int act as a counter variable.

    Write a program to print out how many number of uppercase ,lowercase , and digit present in the

    given string .

    STEP -1 WRITE THE CLASS NAME

    STEP -2 WRITE THE MAIN IN THE PROGRAM

    STEP -3 L = S.LENTH()

    STEP -4 V,G,D,S1 0STEP -5 FOR LOOP I1 TO NSTEP -6 IF(H65 TO 90) V V+1STEP -7 IF(H97 TO 122) L L+1STEP -8 IF(H48 TO 57) D D+1STEP -9 ELSE S1 S1+1STEP -10 PRINT THE V,L,D,S1

    import java.lang.*;

    class Address

    {

    public static void main(String[] args)

    {String s="My address is B/139,Aliganj,Lucknow-266006";

    int l=s.length();

    int u=0,g=0,d=0,s1=0;

    for(int i=0;i=65&&h=97&&h=48&&h

  • 8/6/2019 Write a Program to Print- IMPROV

    6/32

    JAVA PROJECT FILE (X)}

    }

    Output :

    Upper case=4

    Lower case=22Digit=9

    Special case= 7

    Variable Description :

    s string store the string

    l int stores the length of the string.

    i int use for loop

    u int act as a counter variable

    l int act as a counter variable.

    d int act as a counter variable

    s1 int act as a counter variablech char store the each character in the string

    h int stores the ASCII value of each character.

    6

  • 8/6/2019 Write a Program to Print- IMPROV

    7/32

    JAVA PROJECT FILE (X)

    Write a program replace the a particular word in given string.

    STEP -1 WRITE THE CLASS NAME

    STEP -2 WRITE THE MAIN IN THE PROGRAM

    STEP -3 L S.LENTH()STEP -4 PS.INDEXOF("GIRL")STEP -5 STS.SUBSTRING(0,P)STEP -6 STRST+"BOY"STEP -7 PRINT THE STR

    import java.lang.*;

    class Replace

    {

    public static void main(String args[])

    {

    String s="I am a girl";

    int l=s.length();int P=s.indexOf("girl");

    String St=s.substring(0,P);

    String str =St+"boy";

    System.out.println("output is ");

    System.out.println(str);

    }

    }

    Input : I am a girl

    Output : output is I am a boy

    Variable Description :

    s string store the string

    l int stores the length of the string.P int stores the position that character

    St string store the string

    7

  • 8/6/2019 Write a Program to Print- IMPROV

    8/32

    JAVA PROJECT FILE (X)s string store the string

    Sum = x1/2+ x2/3+x100/101

    STEP -1 WRITE THE CLASS NAME

    STEP -2 WRITE THE MAIN IN THE PROGRAM

    STEP -3 TAKES THE VALUE FROM THE USER

    STEP -4 SUM0STEP -5 FOR LOOP I1 TO 100STEP -6 SUM SUM + MATH.POW(X,I)/

    (I+1)

    STEP 7 PRINT THE SUM

    import java.io.*;

    import java.lang.*;

    class series

    {

    public static void main(String args[]) throws IOException{

    int x;

    BufferedReader ob = new BufferedReader (new InputStreamReader(System.in));

    String y=ob. readLine();

    x=Integer.parseInt(y);

    float sum = 0;

    for(int i= 1;i

  • 8/6/2019 Write a Program to Print- IMPROV

    9/32

    JAVA PROJECT FILE (X)

    Write a program to takes 2 integer number from user and print they are twinprime or not

    STEP -1 WRITE THE CLASS NAME

    STEP -2 WRITE THE MAIN IN THE PROGRAM

    STEP -3 TAKES 2 VALUES FROM THE USER

    STEP -4 C10, C20STEP -5 FOR LOOP I1 TO A / FOR LOOP I1

    TO BSTEP -6 IF C1=2,C2=2,A-B=2,B-A=2

    STEP 7 PRINT A,B TWINEPRIME

    STEP -8 ELSE

    STEP 9 PRINT A,B NOT TWINEPRIME

    import java.io.*;

    class Twinprime

    {

    public static void main(String[] args)throws IOException{

    int a,b;

    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

    System.out.println("Enter the 1st no.");

    String x=br.readLine();

    a=Integer.parseInt(x);

    System.out.println("Enter the 2nd no.");

    String y=br.readLine();

    b=Integer.parseInt(y);

    int c1=0;

    for(int i=1;i

  • 8/6/2019 Write a Program to Print- IMPROV

    10/32

    JAVA PROJECT FILE (X)System.out.print(+b);

    System.out.print("are twin prime");

    }

    else

    System.out.print("are not twin prime");

    }

    }

    Input : Enter the 1st no : 11

    Enter the 2nd no :13

    Output : 11,13 are twin prime

    Variable Description :

    i int use for loop

    c1 int act as a counter variable

    c2 int act as a counter variable.

    10

  • 8/6/2019 Write a Program to Print- IMPROV

    11/32

    JAVA PROJECT FILE (X)

    Write a program to takes a integer number from user and print they are palprime or not

    STEP -1 WRITE THE CLASS NAME

    STEP -2 WRITE THE MAIN IN THE PROGRAM

    STEP -3 TAKES VALUE FROM THE USER

    STEP -4 REV0, C20, XASTEP -5 WHILE (A>0)

    STEP -6 INT R A % 10STEP 7 REV REV*10 +RSTEP -8 INT Q A/10STEP 9 A QSTEP 10 IF REV= X

    STEP -11 FOR LOOP I1 TO XSTEP -12 IF C1=2,C2=2,A-B=2,B-A=2

    STEP 13 PRINT A,B TWINEPRIME

    STEP -14 ELSE

    STEP 15 PRINT A,B NOT TWINEPRIME

    import java.io.*;

    class palprime

    {

    public static void main(String[] args) throws IOException

    {

    int x;

    BufferedReader ob = new BufferedReader(new InputStreamReader(System.in));

    String y=ob.readLine();

    x=Integer.parseInt(y);

    int a = x;

    int rev = 0, c =0;

    while (a>0)

    {

    int r = a % 10;

    rev = rev*10 +r;

    int q = a/10;

    a = q;

    }

    if (x == rev)

    { for( int j =1;j

  • 8/6/2019 Write a Program to Print- IMPROV

    12/32

    JAVA PROJECT FILE (X)c = c+1;

    }

    if(c = =2)

    {

    System.out.print(+x );

    System.out.print("is palprime");}

    else

    {

    System.out.print("notpalprimr");

    }

    }

    Variable Description :

    j int use for loop

    c int act as a counter variable

    rev int store the reverse valueq int store the quosent value

    r int store the remainder value

    12

  • 8/6/2019 Write a Program to Print- IMPROV

    13/32

    JAVA PROJECT FILE (X)

    Write a program to takes any number from user and print each digit in alphabetically

    STEP -1 WRITE THE CLASS NAME

    STEP -2 WRITE THE MAIN IN THE PROGRAM

    STEP -3 TAKES THE VALUE FROM THE USER

    STEP -4 R=W%10

    STEP -5 SWITCH(R)STEP 7 PRINT THE OUTPUT

    import java.io.*;

    class Word

    {

    public static void main(String[] args) throws IOException

    {

    int w;

    BufferReader bf=new BufferdReader(new InputStreamReader (System .in));

    System.out.println("Enter the no.");String x =bf.readLine();

    w= Integer.parseInt(x);

    int r=w%10;

    string z;

    switch(r);

    {

    case 0:z="zero";

    break;

    case 1:z="one";

    break;

    case 2:z="two"

    break;

    case 3:z="three";

    break;

    case 4:z="four";

    break;

    case 5:z="five"

    break;

    case 6:z="six";

    break;

    case 7:z="seven";break;

    case 8:z="eight"

    break;

    13

  • 8/6/2019 Write a Program to Print- IMPROV

    14/32

    JAVA PROJECT FILE (X)case 9:z="nine";

    break;

    default: System.out.println("the value is not matching" );

    }

    System.out.println(z);

    }

    }

    Input : Enter the no : 17

    Output : seven

    one

    Variable Description :

    z string store the string

    r int store the remainder value

    14

  • 8/6/2019 Write a Program to Print- IMPROV

    15/32

  • 8/6/2019 Write a Program to Print- IMPROV

    16/32

    JAVA PROJECT FILE (X)

    WAP to enter any block and print how many sentence, vowel, word present in each string

    STEP 1 START THE CLASS

    STEP 2 START THE MAIN

    STEP 3 ENTER THE BLOCK

    STEP 4 SNS+ STEP 5 LSN.LENGTH()STEP 6 V0,W0,ST0STEP 7 FOR(INT I=0;I

  • 8/6/2019 Write a Program to Print- IMPROV

    17/32

    JAVA PROJECT FILE (X)}

    else if (ch==' ')

    W=W+1

    }

    else

    {

    st= st+1;System.out.println(+st" "+V" "+W);

    V=0;

    W=0;

    }

    }

    }

    Input : java is a programming language. BlueJ run java program.

    Output: sentence vowel word1 11 5

    2 7 4

    Variable Description :

    S,Sn string store the string

    l int stores the length of the string.

    V,W,st int act as a counter variable.

    ch char store the each character in the string

    17

  • 8/6/2019 Write a Program to Print- IMPROV

    18/32

    JAVA PROJECT FILE (X)

    Write a program to find the factorial of a number using recursive function

    STEP 1 START THE CLASS

    STEP 2 START THE FUNCTION (INT F)

    STEP 3 IF F = 0 RETURN 0

    STEP 4 ELSE IF F =1 RETURN 1STEP 5 ELSE RETURN F*FACT(F-1)

    STEP 6 START THE MAIN

    STEP 7 ENTER THE VALUES FROM THE USER

    STEP 8 PASS THE PARAMITER THROUGH FUNCTION

    STEP 9 PRINT THE OUTPUT

    import java.io.*;

    class recursion

    {

    int fact(int f)

    {

    if(f==0)

    return 0;

    else

    if(f==1)

    return 1;

    else

    return f*fact(f-1);

    }

    public static void main(String args[])throws IOException{BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));

    recursion r=new recursion();

    System.out.println(Enter any number);

    int n=Integer.parseInt(ob.readLine());

    int f=r.fact(n);

    System.out.println(Factorial of the number is : +f);

    }

    }

    Output

    Enter any number5

    Factorial of the number is : 120

    18

  • 8/6/2019 Write a Program to Print- IMPROV

    19/32

    JAVA PROJECT FILE (X)

    Write a program to create a single dimensional array of n element and print the array elements in

    reverse order.

    STEP 1 START THE CLASS

    STEP 2 START THE MAINSTEP 3 ENTER THE LENTH OF SINGAL

    DIAMENTION ARRAY

    STEP 4 ENTER THE VALUES

    STEP 5 FOR I N-1 TO 0STEP 6 PRINT I

    import java.io.*;

    class array

    {

    public static void main(String args[])throws IOException

    {

    BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));

    int n,i;

    int ar[]=new int[100];

    System.out.println(Enter the length of the array :);

    n=Integer.parseInt(ob.readLine());

    System.out.println(Enter +n+ Elements :);

    for(i=0;i=0;i--)

    {

    System.out.print(ar[i]+ );

    }

    }

    }

    Output

    Enter the length of the array: 5Enter 5 elements

    12

    23

    19

  • 8/6/2019 Write a Program to Print- IMPROV

    20/32

    JAVA PROJECT FILE (X)34

    45

    56

    Array in reverse order

    56 45 34 23 12

    Variable Description :n int stores the length of the array.

    i int stores all numbers from n-1 to 0, act as a counter variable.

    ar[] int Stores n elements.

    20

  • 8/6/2019 Write a Program to Print- IMPROV

    21/32

    JAVA PROJECT FILE (X)

    WAP to create an array of n elements. Enter a number to search in array if found print its position in

    list else print element not found. (Use linear search technique).

    STEP 1 START THE CLASS

    STEP 2 START THE MAIN

    STEP 3 ENTER THE LENTH OF SINGALDIAMENTION ARRAY

    STEP 4 ENTER THE VALUES

    STEP 5 ENTER THE SEARCH VALUE

    STEP 6 FOR I 0 TO NSTEP 7 IF AR[I] = VALUE

    STEP 8 POSITION ISTEP 9 PRINT POSITION

    STEP 10 PRINT VALUE

    import java.io.*;

    class array

    {

    public static void main(String args[])throws IOException

    {

    BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));

    int n,I,num,flag=0;

    int ar[]=new int[100];

    System.out.println(Enter the length of the array :);

    n=Integer.parseInt(ob.readLine());

    System.out.println(Enter +n+ Elements :);for(i=0;i

  • 8/6/2019 Write a Program to Print- IMPROV

    22/32

    JAVA PROJECT FILE (X)if(flag==1)

    System.out.println(The number is found at position :+(i+1));

    else

    System.out.println(The number is not found);

    }

    }

    Output

    Enter the length of the array: 5

    Enter 5 elements

    12

    23

    34

    45

    56

    Enter a number to be Searched : 34The number is found at position : 3

    22

  • 8/6/2019 Write a Program to Print- IMPROV

    23/32

    JAVA PROJECT FILE (X)

    WAP to create an array of n elements. Enter a number to search in array if found print its position in

    list else print element not found. (Use Binary search technique).

    STEP 1 START THE CLASS

    STEP 2 START THE MAIN

    STEP 3 ENTER THE LENTH OF SINGALDIAMENTION ARRAY

    STEP 4 ENTER THE VALUES

    STEP 5 ENTER THE SEARCH VALUE

    STEP 6 FOR I 0 TO NSTEP 7 IF AR[I] = VALUE

    STEP 8 POSITION ISTEP 9 PRINT POSITION

    STEP 10 PRINT VALUE

    STEP 11 ELSE

    STEP 12 NOT FOUND THE ENTERED NUMBER

    import java.io.*;

    class array

    {

    public static void main(String args[])throws IOException

    {

    BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));

    int n,I,U,mid,num,flag=0;

    int ar[]=new int[100];

    System.out.println(Enter the length of the array :);n=Integer.parseInt(ob.readLine());

    System.out.println(Enter +n+ Elements :);

    for(i=0;i

  • 8/6/2019 Write a Program to Print- IMPROV

    24/32

    JAVA PROJECT FILE (X){

    flag=1;

    break;

    }

    else if(ar[mid]>num)

    {

    U=mid-1;}

    else

    {

    L=mid+1;

    }

    }

    if(flag==1) System.out.println(The number is found at position :+(mid+1));

    else System.out.println(The number is not found);

    }

    }

    Output

    Enter the length of the array: 5

    Enter 5 elements

    12

    23

    34

    45

    56

    Enter a number to be Searched : 34

    The number is found at position : 3

    Variable Description :

    n int stores the length of the array.

    ar[] int Stores n elements.

    num int Store the number inputted by the user to search.

    flag int Status variable becomes 1 when the number if found else 0.

    L int Store the value of upper bound.

    U int Store the value of Lower bound.

    Mid int Stores the middleposition of the array.

    24

  • 8/6/2019 Write a Program to Print- IMPROV

    25/32

    JAVA PROJECT FILE (X)

    WAP to create an array of n elements and print the array in ascending order using using bubble sort

    technique.

    STEP 1 START THE CLASS

    STEP 2 START THE MAINSTEP 3 ENTER THE LENTH OF SINGAL DIAMENTION

    ARRAY

    STEP 4 ENTER THE VALUES

    STEP 5 TEMP 0STEP 6 FOR I 0 TO NSTEP 7 FOR J 0 TO N-ISTEP 8 IF(AR[J]>AR[J+1])

    STEP 9 TEMPAR[J]STEP 10 AR[J]AR[J+1]STEP 11 AR[J+1]TEMPSTEP 12 PRINT THE ARRAY IN SORTED ORDER

    import java.io.*;

    class array

    {

    public static void main(String args[])throws IOException

    {

    BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));

    int n,i,j,temp;

    int ar[]=new int[100];System.out.println(Enter the length of the array :);

    n=Integer.parseInt(ob.readLine());

    System.out.println(Enter +n+ Elements :);

    for(i=0;i

  • 8/6/2019 Write a Program to Print- IMPROV

    26/32

    JAVA PROJECT FILE (X)temp=ar[j];

    ar[j]=ar[j+1];

    ar[j+1]=temp;

    }}}

    System.out.println(Sorted array is :);

    for(i=0;i

  • 8/6/2019 Write a Program to Print- IMPROV

    27/32

    JAVA PROJECT FILE (X)

    WAP create an array of n elements and print the array in ascending order using selection sort

    technique.

    STEP 1 START THE CLASSSTEP 2 START THE MAIN

    STEP 3 ENTER THE LENTH OF SINGAL DIAMENTION

    ARRAY

    STEP 4 ENTER THE VALUES

    STEP 5 TEMP 0STEP 6 FOR I 0 TO NSTEP 7 FOR J I+1 TO NSTEP 8 IF(AR[J]>AR[J+1])

    STEP 9 TEMPAR[J]STEP 10 AR[J]AR[J+1]STEP 11 AR[J+1]TEMPSTEP 12 PRINT THE ARRAY IN SORTED ORDER

    import java.io.*;

    class array

    {

    public static void main(String args[])throws IOException

    {

    BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));

    int n,i,j,temp;int ar[]=new int[100];

    System.out.println(Enter the length of the array :);

    n=Integer.parseInt(ob.readLine());

    System.out.println(Enter +n+ Elements :);

    for(i=0;i

  • 8/6/2019 Write a Program to Print- IMPROV

    28/32

    JAVA PROJECT FILE (X){

    temp=ar[i];

    ar[i]=ar[j];

    ar[j]=temp;

    }

    }

    }}

    System.out.println(Sorted array is :);

    for(i=0;i

  • 8/6/2019 Write a Program to Print- IMPROV

    29/32

    JAVA PROJECT FILE (X)

    Program to create an array of n elements and print the sum of all elements.

    STEP 1 START THE CLASSSTEP 2 START THE MAIN

    STEP 3 ENTER THE LENTH OF SINGAL DIAMENTION

    ARRAY

    STEP 4 ENTER THE VALUES

    STEP 5 SUM 0STEP 6 FOR I 0 TO NSTEP 7 SUMSUM+ AR[I]STEP 8 PRINT THE SUM

    import java.io.*;

    class array

    {

    public static void main(String args[])throws IOException

    {

    BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));

    int n,i,sum=0;

    int ar[]=new int[100];

    System.out.println(Enter the length of the array :);

    n=Integer.parseInt(ob.readLine());

    System.out.println(Enter +n+ Elements :);for(i=0;i

  • 8/6/2019 Write a Program to Print- IMPROV

    30/32

    JAVA PROJECT FILE (X)30

    40

    50

    Sum is : 150

    Variable Description :

    n int stores the length of the array.ar[] int Stores n elements.

    i int stores all numbers from 1 to n, act as a counter variable.

    sum int Store the sum of n elements.

    WAP implement function Overloading.

    STEP 1 START THE CLASSSTEP 2 START THE FUNCTION (DOUBLE R)

    STEP 3 START THE FUNCTION (FLOAT L, FLOAT B)

    STEP 4 START THE FUNCTION (FLOAT S)

    STEP 5 START THE MAIN

    STEP 6 ENTER THE VALUES FROM THE USER

    STEP 7 PASS THE PARAMITER THROUGH FUNCTION

    STEP 8 PRINT THE OUTPUT

    import java.io.*;

    public class overloading

    {

    float area(double r)

    { return(float)3.14*r*r;

    }

    float area(float l,float b)

    { return l*b;

    }

    float area(float s)

    { return s*s;

    }public static void main(String args[])throws IOException

    {

    BufferedReaderob=newBufferedReader(newinputStreamReader(System.in));

    overloading o=new overloading();

    System.out.println(1.Area of circle);

    System.out.println(2.Area of rectangle);

    System.out.println(3.Area of square);

    System.out.println(Enter your choice);

    int ch=Integer.parseInt(ob.readLine());

    float a=0;switch(ch)

    {

    case 1:System.out.println(Enter the radius);

    30

  • 8/6/2019 Write a Program to Print- IMPROV

    31/32

    JAVA PROJECT FILE (X)Double r=Double.parseDouble(ob.readLine());

    a=o.area(r);

    break;

    case 2:System.out.println(Enter the length and breadth);

    float l=Float.parseFloat(ob.readLine());

    float b=Float.parseFloat(ob.readLine());

    a=o.area(l,b);break;

    case 3: System.out.println(Enter the side);

    float s= Float.parseFloat(ob.readLine());

    a=o.area(s);

    break;

    }

    System.out.println(The area is+a);

    }

    }

    Output1.Area of circle

    2.Area of rectangle

    3.Area of square

    Enter your choice

    1

    Enter the radius

    4

    The area is 50.24

    31

  • 8/6/2019 Write a Program to Print- IMPROV

    32/32

    JAVA PROJECT FILE (X)