Program showing use of Arithmetic Operator
class arithoper
{
public static void main(String[] args)
{
short x=6;
int y=4;
float a=12.5f;
float b=7.2f;
[Link]("value of x is :"+x+" value of y is :"+y);
[Link]("x+y ="+(x+y));
[Link]("x-y ="+(x-y));
[Link]("x*y ="+(x*y));
[Link]("x%y ="+(x%y));
x=-6;
[Link]("x%y ="+(x%y));
y=-4;
}
}
Program showing simple test variable
class testvar
{
public static void main(String[] args)
{
float rate=5;
double amt=10000;
amt=rate*amt;
[Link]("rate"+rate);
[Link]("amt"+amt);
}
}
Program for Even Odd number
class even
{
public static void main(String[] args)
{
int x=12;
if(x%2==0)
{
[Link](x);
[Link](" is even ");
}
else
{
[Link](x);
[Link](" is odd ");
}
}
}
Program for simple array object
class array1
{
public static void main(String[] s)
{
int marks[];
marks=new int[7];
for(int i=0;i<7;i++)
[Link]("marks["+i+"] is "+marks[i]);
}
}
Program creating objects of class String using various constructors
class string1
{
public static void main(String[] s)
{
char name[]={'j','a','v','a'};
String str1=new String();
String str2=new String(name);
String str3=new String(name,1,2);
String str4=new String(str3);
String str5=new String("JAVA");
[Link]("str1 is :"+str1);
[Link]("str2 is :"+str2);
[Link]("str3 is :"+str3);
[Link]("str4 is :"+str4);
[Link]("str5 is :"+str5);
}
}
Program for comparing strings using methods of class String
class strcomp
{
public static void main(String[] s)
{
String str1="India is great";
String str2="INDIA IS GREAT";
[Link]("str1:"+str1);
[Link]("str2:"+str2);
[Link]("[Link](str2):"+[Link](str2));
[Link]("[Link](str2):"+[Link](str2));
}
}
Program for String conversion methods
class strcon
{
public static void main(String[] s)
{
String str1="I like Java";
[Link]("Given string is \""+str1+"\"");
[Link]("String in lowercase: \""+[Link]()+"\"");
[Link]("String in uppercase: \""+[Link]()+"\"");
}
}