Sunday, March 22, 2015

Count Vowels from a String, Use Constructor

Write a Java Program to Count the Number of Vowels in a given string. Use Constructor, Instances and Method, if necessary. Do not use any parameter with Constructor.

Reference: 
1.  Course Book(The Complete Reference Java j2se) ; Page 118

2. http://c-programming-sourcecode.blogspot.com/2014/12/count-number-of-vowels.html?updated-min=2014-12-01T00:00:00-08:00&updated-max=2015-01-01T00:00:00-08:00&max-results=41

Java Source Code:

package vowel;
import java.util.Scanner;
class CountVowels
{
int count =0;
String str;
CountVowels()
{
str="Bangladesh" ;
}
void get()
{
for (int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);
if (ch == 'a' || ch == 'e' || ch == 'i' ||
ch == 'o' || ch == 'u' || ch == 'A' ||
ch == 'E' || ch == 'I' || ch == 'O' ||
ch == 'U')
count++;

}
System.out.println("Enter String is " + str);
System.out.println("Number of vowel of "+str+ " is : " + count);
}
}

public class vowel{
public static void main(String[]args){
CountVowels vol = new CountVowels();
vol.get();
}
}

16 comments:


  1. package javainheritence;
    class imam
    {
    int a, b;
    void show1()
    {
    System.out.println("Value of a b =" +a +" " +b);
    }
    }

    class shahin extends imam
    {
    int m;
    void show2()
    {
    System.out.println("Valu of m =" + m);
    }
    void sum()
    {
    System.out.println("Sum of a b m =" +(a+b+m));
    }
    }
    public class JavaInheritence {



    public static void main(String[] args)
    {
    imam input=new imam();
    shahin input1=new shahin();
    input.a=40;
    input.b=60;
    System.out.println();
    input1.a=20;
    input1.b=30;
    input1.m=50;
    System.out.println("Value of abm");
    input.show1();
    input1.show2();
    System.out.println();
    System.out.println("The sum is=");
    input1.sum();

    }

    ReplyDelete
  2. ID:201420406
    Batch:46th

    class Box
    {
    double width;
    double height;
    double depth;
    Box() {
    System.out.println("Constructing Box");
    width = 20;
    height = 20;
    depth = 20;
    }
    double volume() {
    return width * height * depth;
    }
    }
    class BoxDemo6 {
    public static void main(String args[])
    {
    Box mybox1 = new Box();
    Box mybox2 = new Box();
    double vol;
    vol = mybox1.volume();
    System.out.println("Volume is " + vol);
    vol = mybox2.volume();
    System.out.println("Volume is " + vol);
    }
    }

    ReplyDelete
  3. ID:201421066
    Batch:46th

    package inheritence;
    class inher
    {
    int m, n;
    void display1()
    {
    System.out.println("Value of m n =" +m +" " +n);
    }
    }

    class hasmot extends inher
    {
    int p;
    void display2()
    {
    System.out.println("Valu of p =" + p);
    }
    void sum()
    {
    System.out.println("Sum of m n p =" +(m+n+p));
    }
    }
    public class Inheritence {



    public static void main(String[] args)
    {
    inher input=new inher();
    hasmot input1=new hasmot();
    input.m=40;
    input.n=60;
    System.out.println();
    input1.m=20;
    input1.n=30;
    input1.p=50;
    System.out.println("Value of mnp");
    input.display1();
    input1.display2();
    System.out.println();
    System.out.println("The result is=");
    input1.sum();

    }

    ReplyDelete
  4. package javaconstructing;
    class Box
    {
    double width;
    double height;
    double depth;

    Box()
    {
    System.out.println("Constructing Box");
    width =10;
    height =20;
    depth =05;
    }
    double volume()
    {
    return width*height*depth;
    }
    }

    class Boxdemo6
    {
    public static void main(String[] args)
    {
    Box box1=new Box();
    Box box2=new Box();
    // System.out.println();

    double vol;
    vol = box1.volume();
    System.out.println("Volume is=" + vol);

    vol= box2.volume();
    System.out.println("Volume is=" + vol);

    }
    }

    ReplyDelete
  5. Batch-46th
    ID-201420270

    package javaconstructing;
    class Box
    {
    double width;
    double height;
    double depth;
    Box()
    {
    System.out.println("Constructing Box");
    width =10;
    height =20;
    depth =10;
    }
    double volume()
    {
    return width*height*depth;
    }
    }
    class Boxdemo6
    {
    public static void main(String[] args)
    {
    Box box1=new Box();
    Box box2=new Box();
    double vol;
    vol = box1.volume();
    System.out.println("Volume is=" + vol);
    vol= box2.volume();
    System.out.println("Volume is=" + vol);

    }
    }

    ReplyDelete
  6. Batch-46th
    ID-201420674

    class Box
    {
    double width;
    double height;
    double depth;
    Box() {
    System.out.println("Constructing Box");
    width = 10;
    height = 10;
    depth = 10;
    }
    double volume() {
    return width * height * depth;
    }
    }
    class BoxDemo6 {
    public static void main(String args[])
    {
    Box mybox1 = new Box();
    Box mybox2 = new Box();
    double vol;
    vol = mybox1.volume();
    System.out.println("Volume is " + vol);
    vol = mybox2.volume();
    System.out.println("Volume is " + vol);
    }
    }

    ReplyDelete
  7. Q:Write a Program Java using constractor :

    package cons;
    class sobuj
    {
    double width;
    double height;
    double depth;
    sobuj( double w, double h, double d)
    {
    width=w;
    height=h;
    depth=d;
    }
    double volume()
    {
    return width*height*depth;
    }
    }
    public class cons {
    public static void main(String[] args) {
    // TODO code application logic here
    sobuj mybox1 = new sobuj(15,16,18);
    sobuj mybox2 = new sobuj(25,26,28);
    double vol;

    vol = mybox1.volume();
    System.out.println("Volume of box1 is: " +vol);

    vol = mybox2.volume();
    System.out.println("\nVolume of box2 is: "+vol);
    System.out.println();
    }
    }

    ReplyDelete
  8. package vowel;
    import java.util.Scanner;
    class CountVowels
    {
    int count =0;
    String str;
    CountVowels()
    {
    str="Bangladesh" ;
    }
    void get()
    {
    for (int i = 0; i < str.length(); i++) {
    char ch = str.charAt(i);
    if (ch == 'a' || ch == 'e' || ch == 'i' ||
    ch == 'o' || ch == 'u' || ch == 'A' ||
    ch == 'E' || ch == 'I' || ch == 'O' ||
    ch == 'U')
    count++;

    }
    System.out.println("Enter String is " + str);
    System.out.println("Number of vowel of "+str+ " is : " + count);
    }
    }

    public class vowel{
    public static void main(String[]args){
    CountVowels vol = new CountVowels();
    vol.get();
    }
    }

    ReplyDelete
  9. Q:Write a Java Program to Count the Number of Vowels in a given string. Use Constructor,
    Instances and Method, if necessary. Do not use any parameter with Constructor.

    package vowel;
    import java.util.Scanner;
    class CountVowels
    {
    int count =0;
    String ss;
    CountVowels()
    {
    ss="Dhaka" ;
    }
    void get()
    {
    for (int i = 0; i < ss.length(); i++)
    {
    char ch = ss.charAt(i);
    if (ch == 'a' || ch == 'e' || ch == 'i' ||
    ch == 'o' || ch == 'u' || ch == 'A' ||
    ch == 'E' || ch == 'I' || ch == 'O' ||
    ch == 'U')
    count++;

    }
    System.out.println("Enter String is " + ss);
    System.out.println("Number of vowel of "+ss+ " is : " + count);
    }
    }

    public class vowel{
    public static void main(String[]args){
    CountVowels vol = new CountVowels();
    vol.get();
    }
    }

    ReplyDelete
  10. Batch-46th
    ID-201421068

    class Box1 {


    double width;
    double height;
    double depth;
    Box1() {
    System.out.println("Constructing Box");
    width = 15;
    height = 115;
    depth = 15;
    }
    double volume() {
    return width * height * depth;
    }
    }
    class BoxDemo6 {
    public static void main(String args[])
    {
    Box1 mybox1 = new Box1();
    Box1 mybox2 = new Box1();
    double vol;
    vol = mybox1.volume();
    System.out.println("Volume is " + vol);
    vol = mybox2.volume();
    System.out.println("Volume is " + vol);
    }
    }

    ReplyDelete
  11. package vowelcount;
    import java.util.Scanner;
    class toma
    {
    void takeVowel()
    {
    int vowel=0;
    String phrase;
    char ch;
    Scanner s=new Scanner(System.in);
    System.out.print("Enter the string:");
    phrase=s.nextLine();
    for(int i=0;i<phrase.length();i++)
    {
    ch=phrase.charAt(i);
    if(ch=='A'|| ch=='E' || ch=='I' || ch=='O' || ch=='U'||
    ch=='a' || ch=='e'|| ch=='i'|| ch=='o' || ch=='u')
    vowel++;
    }
    System.out.println("The number of vowel is: "+vowel);
    }
    }
    public class Vowelcount
    {
    public static void main(String[] args)
    {
    toma t=new toma();
    t.takeVowel();
    }

    }

    ReplyDelete
  12. ID: 201420763
    Batch :46th



    package javaapplication11;


    public class JavaApplication11 {


    public static void main(String[] args) {
    int input1 = sum(5,10);
    int input2 = sum(5,5,20);
    int input3 = sum(10,10,20,50);
    System.out.println("Under the Display Your Input Addition: ");
    System.out.println("1st input Addition:");
    System.out.println(input1 );
    System.out.println("2nd input Addition:");
    System.out.println(input2 );
    System.out.println("3rd input Addition:");
    System.out.println(input3 );

    }
    private static int sum(int... args)
    {
    int ret = 0;

    if (args != null)
    {
    for (int val : args)
    {
    ret += val;
    }
    }
    return ret;
    }

    }

    ReplyDelete
  13. Name -Main Uddin
    id-201421090
    Batch-46
    package exercise.pkg5;
    import java.util.Scanner;
    class VowelsMainCount
    {
    int countNumber =0;
    String InputStr;
    VowelsMainCount(String Value)
    {
    InputStr=Value;
    }
    void Live()
    {
    for (int i = 0; i < InputStr.length(); i++) {
    char ch = InputStr.charAt(i);
    if (ch == 'a' || ch == 'e' || ch == 'i' ||
    ch == 'o' || ch == 'u' || ch == 'A' ||
    ch == 'E' || ch == 'I' || ch == 'O' ||
    ch == 'U')
    countNumber++;

    }
    System.out.println("Enter String is " + InputStr);
    System.out.println("Number of vowel of "+InputStr+ " is : " + countNumber);
    }
    }
    public class Exercise5 {
    public static void main(String[] args) {

    VowelsMainCount GTRDhaka = new VowelsMainCount("Geniune");
    GTRDhaka.Live();
    }

    }

    ReplyDelete
  14. Md : Jalis Mahmud
    ID : 201420762
    Batch : 46th


    package vowelcount;
    import java.util.Scanner;
    class jalis
    {
    void takeVowel()
    {
    int vowel=0;
    String phrase;
    char ja;
    Scanner s=new Scanner(System.in);
    System.out.print("Enter the string:");
    phrase=s.nextLine();
    for(int i=0;i<phrase.length();i++)
    {
    ch=phrase.charAt(i);
    if(ja=='A'|| ja=='E' || ja=='I' || ja=='O' || ja=='U'||
    ja=='a' || ja=='e'|| ja=='i'|| ja=='o' || ja=='u')
    vowel++;
    }
    System.out.println("The number of vowel is: "+vowel);
    }
    }
    public class Vowelcount
    {
    public static void main(String[] args)
    {
    jalis t=new jalis();
    t.takeVowel();
    }

    }

    ReplyDelete
  15. Name : Habibur Rahaman
    ID-201421091
    Batch-46


    package exercise.pkg5;
    import java.util.Scanner;
    class sajibxm
    {
    int num =0;
    String InputStr;
    sajibxm(String Value)
    {
    InputStr=Value;
    }
    void Live()
    {
    for (int i = 0; i < InputStr.length(); i++) {
    char ch1 = InputStr.charAt(i);
    if (ch1 == 'a' || ch1 == 'e' || ch1 == 'i' ||
    ch1 == 'o' || ch1 == 'u' || ch1 == 'A' ||
    ch1 == 'E' || ch1 == 'I' || ch1 == 'O' ||
    ch1 == 'U')
    num++;

    }
    System.out.println("Enter String is " + InputStr);
    System.out.println("Number of vowel of "+InputStr+ " is : " + num);
    }
    }
    public class Exercise5 {
    public static void main(String[] args) {

    sajibxm GTRDhaka = new sajibxm("Geniune");
    GTRDhaka.Live();
    }

    }

    ReplyDelete
  16. ID-201421092
    Batch-46

    package exercise.pkg5;
    import java.util.Scanner;
    class R
    {
    int num =0;
    String InputStr;
    R(String Value)
    {
    InputStr=Value;
    }
    void Live()
    {
    for (int i = 0; i < InputStr.length(); i++) {
    char ch1 = InputStr.charAt(i);
    if (ch1 == 'a' || ch1 == 'e' || ch1 == 'i' ||
    ch1 == 'o' || ch1 == 'u' || ch1 == 'A' ||
    ch1 == 'E' || ch1 == 'I' || ch1 == 'O' ||
    ch1 == 'U')
    num++;

    }
    System.out.println("Enter String is " + InputStr);
    System.out.println("Number of vowel of "+InputStr+ " is : " + num);
    }
    }
    public class Exercise5 {
    public static void main(String[] args) {

    R PLS = new R("Geniune");
    PLS.Live();
    }

    }

    ReplyDelete