Search This Blog

Loading...

Thursday, February 26, 2015

BlueJ program on finding 0's in a number


 In this program, user will enter any number and total number of zeros in the number will be displayed.



import java.io.*;
class Num
{
 int i,num,c=0;
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
 public void take Num () throws Exception
 {
  System.out.println("Enter the number:");
  num=Integer.parseInt(br.readLine());
 
  for(i=num;i>0;i=i/10)
  {
   if(i%10==0)
c++;
}

   System.out.print("Total number of zeros in "+num + " is :"+c);
  }
   public static void main(String args[])throws Exception
  {
   Num ob=new Num ();
   ob.take Num ();
   }

   }

BlueJ program on printing a sentence skipping the vowels


In this program user will enter any sentence and print all the character except the vowels. In case of vowels print the character next to two places of it.



import java.io.*;
class Sentence1
{
 String s1;
 int i,len;
 char ch;
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
 public void take Sentence1() throws Exception
 {
  System.out.println("Enter the Sentence:");
  s1=br.readLine();
  len=s1.length()-1;
  for(i=0;i<=len;i++)
  {
   ch=Character.toLowerCase(s1.charAt(i));
   switch(ch)
   {
    case 'a':
    case 'e':
    case 'i':
    case 'o':
    case 'u':
   System.out.print((char)(s1.charAt(i)+2));
   break;
   default:
   System.out.print(s1.charAt(i));
   }
   }
  }
   public static void main(String args[])throws Exception
  {
   Sentence1 ob=new Sentence1();
   ob.take Sentence1();
   }

   }

CHECK HERE FOR PREVIOUS POSTS

Google+ Followers

Subscribe via email

Enter your email address:

Delivered by FeedBurner