Information Technology Practical
java
PROGRAM-1
Aim:- Program for printing “ Hello World “ on screen.
Code:
package helloworldapp; public class
HelloWorldApp { public static void
main(String[] args) {
} O u t p u t : -
System.out.println("Hello World!");
}
PROGRAM-2
Aim:- Program for calculating the addition of two numbers.
Code:
public class CAL
{
public static void main(String[] args)
int num1 = 5;
int num2 = 15;
int num3;
num3 = num1 + num2;
System.out.println("Sum of these numbers: "+num3);
}
}
O u t p u t :
PROGRAM-3
Aim:- Program for Checking whether the given number is even or odd.
Code:-
public class IfElseExample
{
public static void main(String[] args)
{
int number=13;
if(number%2==0)
System.out.println("even number");
else
System.out.println("odd number");
}
} }
Output:-
PROGRAM-4
Aim:- Program for Checking whether the given year is leap or not.
Software Used:-Apache Netbeans 12.6 Code:-
public class LeapYearExample {
public static void main(String[] args) {
int year=2020; if(((year % 4 ==0) && (year % 100 !=0)) ||
(year % 400==0)) { System.out.println(" LEAP YEAR");
} else { System.out.println("COMMON YEAR"); }
}
}
Output:-
PROGRAM-5
Aim:- Program for Checking whether the given number is prime or not.
Software Used:-Apache Netbeans 12.6 Code:- public class prime
{
public static void main(String[] args)
{
int num = 29;
int flag = 0;
for (int i = 2; i <= num / 2; ++i)
{
if (num % i == 0)
{
flag = 1;
break;
}
}
if (flag==1)
System.out.println(num + " is a prime number.");
else
System.out.println(num + " is not a prime number.");
}
}
Output:-
PROGRAM-6
Aim:- Program for calculating percentage of students and check whether the student is passed or
failed.
Software Used:-Apache Netbeans 12.6
Code:-
public class NewMain
{
public static void main(String[] args)
int total=400;
int g=120;
int percentage=0;
percentage=(g/total)*100;
System.out.println(percentage);
if (percentage>= 40)
System.out.println("PASSED");
else
System.out.println("FAILED");
} }}
Output:-
PROGRAM:-7
Aim:- Program for printing Table of 5 on screen.
Software Used:-Apache Netbeans 12.6
Code:
public class table
{
public static void main(String[] args)
int num = 5;
for(int i = 1; i <= 10; ++i)
{
System.out.printf("%d * %d = %d \n", num, i, num * i);
}
}
O u t p u t :
PROGRAM-8
Aim:- Program for finding out day of the week based on the number provided .
Software Used:-Apache Netbeans 12.6
Code:-
public class days
{
public static void main(String[] args) {
{
int today = 5; String day = ""; switch (today) { case 1: day = "Monday"; break; case 2:
day = "Tuesday"; break; case 3: day = "Wednesday"; break; case 4: day =
"Thursday"; break; case 5: day = "Friday"; break; case 6: day = "Saturday"; break;
case 7: day = "Sunday"; break; default: day = "Incorrect Day"; break; }
System.out.println (day);
}
}
Output:
PROGRAM-9
Aim: write a program for showing functionality of Array.
Code:
public class arrays
{
public static void main(String[] args)
{
int[] age = {12, 4, 5, 2, 5};
System.out.println("Accessing Elements of Array:");
System.out.println("First Element: " + age[0]);
System.out.println("Second Element: " + age[1]);
System.out.println("Third Element: " + age[2]);
System.out.println("Fourth Element: " + age[3]);
System.out.println("Fifth Element: " + age[4]);
}
}
Output:-
PROGRAM-10
Aim:- Program for calculating are of rectangle by using user defined method .
Software Used:-Apache Netbeans 12.6
Code:-
public class area
{
static double rectangle_area (double length, double breadth)
{
return (length * breadth);
}
public static void main(String[] args)
{
double a = 0;
a = rectangle_area(45.5, 78.5);
System.out.println("Area of the rectangle = "+ a);
}
Output:-
:
PROGRAM-11
Aim:- Program for creating a class and object in Java .
Software Used:-Apache Netbeans 12.6
Code:-
public class class1
{
int id=101;
String name="Ram";
public static void main(String args[])
class1 s1=new class1();
System.out.println(s1.id);
System.out.println(s1.name);
}
Output:
PROGRAM-12
Aim:- Program for creating a class and object for printing name and age of person in Java .
Software Used:-Apache Netbeans 12.6
Code:-
public class empname
{
String fname = "John";
String lname = "Doe";
int age = 24;
public static void main(String[] args)
empname myObj = new empname();
System.out.println("Name: " + myObj.fname + " " + myObj.lname);
System.out.println("Age: " + myObj.age);
}
}
Output:-
PROGRAM-13
Aim:- Program for converting uppercase string in lower case string in Java .
Software Used:-Apache Netbeans 12.6
Code:-
public class string1
{
public static void main(String[] args) {
String txt = "Hello World";
System.out.println(txt.toUpperCase());
System.out.println(txt.toLowerCase());
}
}
Output:-
PROGRAM-14
Aim:- Program for concatenation of two strings in Java .
Software Used:-Apache Netbeans 12.6
Code:-
public class concat
{
public static void main(String[] args)
String first = "Hello ";
System.out.println("First String: " + first);
String second = "World";
System.out.println("Second String: " + second);
String joinedString = first.concat(second);
System.out.println("Joined String: " + joinedString);
}
}
Output:-
PROGRAM-15
Aim:- Program for checking whether the given string is palindrome in Java .
Software Used:-Apache Netbeans 12.6
Code:-
public class palindrome
{
public static void main(String args[])
int r,sum=0,temp;
int n=454;
temp=n;
while(n>0)
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
System.out.println("palindrome number ");
else
System.out.println("not palindrome");
}
}
Output:-