Java Practical
Java Practical
System.out.println(num1);
System.out.println(num2);
P2. Write a program to show use of Switch Statement and Continue Statement.
import java.util.Scanner;
public class P2 {
public static void main(String[] args) {
String Day;
Scanner in = new
Scanner(System.in); int value =
in.nextInt();
int id =
in.nextInt(); switch
(value) {
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 = "Invalid Input";
}
System.out.println(Day);
for(int i=1;i<=5;i+
+){ if(i==2)
{
continue;
}
System.out.println(i);
}
}
}
P3. Write a program to calculate the area of two different rectangles using class and objects. All basic initialization
and operations will be performed by creating a constructor and methods respectively.
import java.util.Scanner;
class P3
{
int area,length,breadth;
P3()
{
length=10;
breadth=20;
}
P3(int l, int b)
{
length=l;
breadth=b;
}
void area()
{
area = length*breadth;
System.out.println(area);
}
public static void main(String args[])
{
P3 r1=new P3();
P3 r2=new P3(15,15);
P4. Write a program to show how methods can return object and how methods can pass objects as argument using
class and object concept.
import java.util.Scanner;
class ObjectPass
{ int a, b;
ObjectPass(int i, int j)
{
a=
i; b
= j;
}
boolean equalTo(ObjectPass op)
{
return (op.a == a && op.b == b);
}
}
public class P4 {
}
}
" + obj2.equalTo(obj4));
}
}
P5. Write a program to show code reusability by using Inheritance.
import java.util.Scanner;
class
Car {
float Price=400000;
}
P6. Write a program to show string handling (Character Extraction and String
Comparison). import java.util.Scanner;
public class P6 {
}
}
P7. Write a program to show Streams basics in
java. import java.util.*;
import java.util.stream.*;
public class P7 {
public static void main(String args[])
{
//list of integers Creation
List<Integer> number = Arrays.asList(10,23,11,8,6);