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

Saturday 25 June 2011

Java program to cast integer into short and byte data type


import java.util.*;
class casting
{
public static void main (String arg[])
{
Scanner in = new Scanner (System.in);
int a;
short b;
byte c;

System.out.print ("\n\t Enter the value = ");
a=in.nextInt();

b=(short)a;
c=(byte)a;

System.out.println ("\n\t value of a in short form = "+b);
System.out.println ("\n\t Value of a in byte form= "+c);

}
}

Note:
         In the above program you might have noticed these two statements
  • b=(short)a;
  • c=(byte)a;
these are the actual statements that are casting the data type of a into short and byte.

No comments:

Post a Comment

Share