Tuesday, November 25, 2014

Print numbers between 1 to 100 but print "fizz" in place 3 multiplier , print "buzz" in place 5 multiplier ,print "fizz buzz" in place 15 multiplier ?


public class fizzbuzz {
public static void main(String a[]){
for(int i=1;i<=100;i++)
{
if(i%15==0)
        System.out.println("fizz buzz");
else if(i%5==0)
System.out.println("Buzz");        
else if(i%3==0)                       
           System.out.println("fizz");
        else{
          System.out.println(i);
    }
          }  
    }
     }

Friday, November 21, 2014

What is final modifier?

The final modifier keyword makes that the programmer cannot change the value
anymore. The actual meaning depends on whether it is applied to a class, a
variable, or a method.
  1. · final Classes- A final class cannot have sub classes.
  2. · final Variables- A final variable cannot be changed once it is initialized.
  3. · final Methods- A final method cannot be overridden by sub classes.

Why it show exception followed by (hello kkk bye) & Why we use finally ?

public class exception {
    public static void main(String[] args) {
        System.out.println("hello");
        try{ System.out.println("kkk");
            int i = 5/0;
         
        }
        catch(NullPointerException e)
        {
            System.out.println(e);
        }
        finally{
                    System.out.println("bye");
                    }
        System.out.println("no");
        }
    }