Search This Blog

UI/UX Design | Web Development | Mobile Application Development

Whether you need UI/ UX design, web development services, or mobile app development services, Qaabil Digitals will be more than happy to help you. We work with top software developers, designers, and project managers. We tailor our services to suit your exact needs. We closely look at your company, listen to your story, and bring about the best ideas and solutions that can help you drive solid results. We don’t just produce work that works. We produce work that matters. Get a quote now Or Talk to us

Monday, 13 June 2011

Using psot/prefix decrement operator in java program


class apdecrement
{
public static void main (String arg[])
{
int a=97,b=23;
int c,d;
c=--a;
d=b--;
System.out.println ("\n\t a = "+a);
System.out.println ("\n\t b = "+b);
System.out.println ("\n\t c = "+c);
System.out.println ("\n\t d = "+d);
}
}


Note:
          After executing this program you will see the decrement in the values of 'a' , 'b' and 'c' but value of 'd' will as it is. Just like post fix increment increases value after it is used, post fix decrement also do so but it decreases the value by 1 after it is used.

Using post/prefix increment operator in java program


class apincrement
{
public static void main (String arg[])
{
int a=15,b=34;
int d,e;
d=++a;
e=b++;
System.out.println ("\n\t a = "+a);
System.out.println ("\n\t b = "+b);
System.out.println ("\n\t d = "+d);
System.out.println ("\n\t e = "+e);
}
}


Note:
         When you will execute this program you will see that values of 'a' , 'b' and 'd' are increased by 1 but value of 'e' is same as we initialized it by 34. The reason behind this is we are using post fix increment operator. In case of post fix increment value of the variable is used first and then it is increased by 1.

 

Using modulus or '%' operator in java program


class apmodulus
{
public static void main (String arg[])
{
int a=15,b;
b=a%5;
if (b==0)
System.out.println ("\n\t Divisible by 5 ");
else
System.out.println ("\n\t Not divisible by 5 ");
}
}

Note:
          Modulus operator returns remainder. In the above program variable 'a' will be divided by 5. If 5 divides 'a' properly (with out returning any decimal answer) then the message "Divisible by 5" will be showed otherwise statement associated with 'else' will be executed.

Using switch statement in java

import java.util.*;
class apswitch
{
public static void main (String arg[])
{
Scanner in = new Scanner (System.in);
int a;
System.out.print ("\n\t Enter the number = ");
a=in.nextInt();
switch (a)
{
case 1:
System.out.println ("\n\t One ");
break;
case 2:
System.out.println ("\n\t Two");
break;
case 3:
System.out.println ("\n\t Three");
break;
case 4:
System.out.println ("\n\t Four ");
break;
case 5:
System.out.println ("\n\t Five ");
break;
default:
System.out.println ("\n\t Out of range ");
}

}
Share