GOVERNMENT ARTS AND SCIENCE COLLEGE
KOVILPATTI – 628 503.
Department of Computer Science (UG & PG)
E-Content for
CC8 - Practical - Java Programming for II BSc(CS)
[Link]., M.C.A., [Link]., Ph.D.,
Lap Program Guest Lecturer of Computer Science (UG & PG)
Some Common Programs using Java Government Arts and Science College, Kovilpatti.
E-Mail:sevugapandi1985@[Link]. Mobile:9600412482
Write a program to display any message
class Simout
{
public static void main (String args[ ] )
{
[Link]("Welcome to Java programming");
}
}
2. Write a Java program to display default value of all primitive data types of Java.
3. Write a program check two strings are equal or not.
4. Write a program to give the examples of operators.
1. Increment and decrement operators.
2. Bitwise Complement Operator.
3. Arithmetic operator.
4. Bitwise operator. Relational Operator
5. Conditional Operator.
Write a program to give the example of control statements.
1. If statements.
2. Switch Statements.
3. For loop.
4. While Statements.
5. Do statements
Write a program to calculate the following
1. Find the length of array.
2. Demonstrate a one-dimensional array.
3. Demonstrate a two-dimensional array.
class Length
{
public static void main (String[] args)
{
int[] num1 = new int[10];
int[] num2 = { 3,5,7, 1, 8, 99 , 44, -10 };
int[] num3 = { 4, 3, 2, 1 };
//length is an Array attribute that determines the array length
int arrayLength1=[Link];
int arrayLength2=[Link];
int arrayLength3=[Link];
//prints array length
[Link]("The length of the array is: "+ arrayLength1);
[Link]("The length of the array is: "+ arrayLength2);
[Link]("The length of the array is: "+ arrayLength3);
}
// Demonstrate a one-dimensional array.
class onedArray
{
public static void main (String[] args)
{
int num[];
int i;
int size =5;
num = new int[size];
num[0]=10;
num[1]=20;
num[2]=30;
num[3]=40;
num[4]=50;
for (i=0; i<size; i++)
[Link] ("num ["+i+"] =" + num[i]);
}
}
// Demonstrate a two-dimensional array.
class TwoDArray
{
public static void main(String[] args)
{
int[][] twoD = new int[3][3];
int i=0;
int j=0;
int k=0;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{ twoD[i][j]=k;
k++;
} for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
[Link](twoD[i][j] + " ");
[Link]();
}
}
}
// Demonstrate a three-dimensional array.
class ThreeDArray
{
public static void main(String[] args)
{int[][][] twoD = new int[3][3][3];
int i=0; int j=0; int k=0; int l=0;
for(i=0;i<3;i++)
{for(j=0;j<3;j++){
for(l=0;l<3;l++){ twoD[i][j][l]=k; k++; } }
}for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(l=0;l<3;l++)
[Link](twoD[i][j][l] + " ");
[Link]();
}[Link]();
}
}
}
How to take number input in Java
import [Link].*;
import [Link];
class gettheinput
{ // main function
public static void main(String[] args)
{ // Declare the variables
int num;
// Input the integer
[Link]("Enter the integer: ");
// Create Scanner object
Scanner s = new Scanner([Link]);
// Read the next integer from the screen
num = [Link]();
// Display the integer
[Link]("Entered integer is: " + num);
}
}
How to take String input in Java
import [Link].*;
import [Link];
class gettheinputstring
{ // main function
public static void main(String[] args)
{ // Declare the variables
String str;
// Input the integer
[Link]("Enter the String: ");
// Create Scanner object
Scanner s = new Scanner([Link]);
// Read the next string from the screen
str = [Link]();
// Display the string
[Link]("Entered String is: " +str);
}
}
GOVERNMENT ARTS AND SCIENCE COLLEGE,
KOVILPATTI – 628 503.
Department of Computer Science (UG & PG)
E-Content for
CC8 - Practical - Java Programming for II
BSc(CS)
[Link]., M.C.A., [Link]., Ph.D.,
Next Lap Program Guest Lecturer of Computer Science (UG & PG)
1. Write a JAVA program using Multiple Government Arts and Science College, Kovilpatti.
Constructors E-Mail:sevugapandi1985@[Link]. Mobile:9600412482