Java - Manual 1to13
Java - Manual 1to13
Java - Manual 1to13
Experiment-1
Output:-
Hello World
Experiment-2
Program:-
importjava.util.Scanner;
class exp2
{
public static void main(String arg[])
{
inta,b,c,max;
max=(a>b)?((a>c)?a:c):((b>c)?b:c);
System.out.println("Maximum value is:"+max);
}
}
Output:-
Experiment-3
AIM: Write a program in Java to reverse the digits of a number using while
loop.
Program:-
Import java.util.Scanner;
class exp3
{
public static void main(String arg[])
{
intn,ans=0,r;
System.out.println("Enter value");
Scanner s1=new Scanner(System.in);
n=s1.nextInt();
while(n>0)
{
r=n%10;
ans=ans*10+r;
n=n/10;
}
System.out.println("Answer is:"+ans);
}
}
Output:-
Experiment-4
}
System.out.println("Enter the elements of matrix2");
i=0;
while ( i < row)
{
j=0;
while(j < col)
{
mat2[i][j] = in.nextInt();
j++;
}
i++;
i=0;
while ( i < row)
{
j=0;
while(j < col)
{
System.out.println("Sum of matrices:-");
i=0;
while ( i < row)
{
j=0;
Computer Engineering Department Page 5
Java Programming (3350703)
System.out.print(res[i][j]+"\t");
j++;
}
System.out.println();
i++;
}
}
Experiment-5
class exp5
{
staticint count=0;
while(count<n)
{
prime(j);
j++;
}
}
}
}
if(flag==0)
{
count++;
System.out.println(x);
}
}
}
Output:-
Experiment-6
AIM: Write a program in Java which has a class Student having two instance
variables enrollmentNo and name. Create 3 objects of Student class in main
method and display student’s name.
Program:-
Experiment-7
Computer Engineering Department Page 10
Java Programming (3350703)
AIM: Write a program in Java which has a class Rectangle having two
instance variables height and weight. Initialize the class using constructor.
Program:-
public class Rectangle {
private int height;
private int width;
Experiment-8
Experiment-9
// static variable
static int max = 10;
// non-static variable
int min = 5;
}
Experiment-10
AIM: Write a program in Java to demonstrate the use of "final" keyword.
Computer Engineering Department Page 13
Java Programming (3350703)
Program:-
1. Java final Variable
class Main {
public static void main(String[] args) {
obj.display();
}
}
Experiment-11
AIM: Write a program in Java which has a class Shape having 2 overloaded
methods area(float radius) and area(float length, float width). Display the
area of circle and rectangle using overloaded methods.
Program:-
class Shape
{
Experiment-12
Experiment-13
// create a string
String str = "Hello! World";
System.out.println("String: " + str);