UNIT-II-JAVA
UNIT-II-JAVA
Data Types: Every variable in java has a data type. Data types specify the size
and type of value that can be stored in a variable. Java language is rich in its
data types and there are two types of data types. They are
1. Primitive data types
2. Non-primitive data types
The classification of data types in java are shown in figure below.
Numeric data types: In Java, six of the eight primitive data types are numeric
types. Numeric data types are classified into two types. They are
1. Integer data types
2. Floating point data types
Integer data types: Integer data types are used to store whole numbers that
have no fractional part. Integer data types are classified into four types. They
are
1. byte
2. short
3. int
4. long
byte: byte data type is an 8-bit signed integer number. The negative numbers
are expressed in two‘s complement form. The range accepted by byte is -128
to127 i.e. -27 to 27-1. Default value stored in byte variable is 0. byte data type is
used to save space in large arrays, mainly in place of integers, since a byte is
four times smaller than an integer.
Ex: byte a = 100, byte b = -50
short: short data type is a 16-bit signed integer number. The negative
numbers are expressed in two‘s complement form. The range accepted by
byte is -32,768 to 32,767 i.e. -215 to 215-1. Default value stored in short
variable is 0.
Ex: short s = 10000, short r = -20000
int: int data type is a 32-bit signed integer number. The negative numbers are
expressed in two‘s complement form. The range accepted by int is -
2,147,483,648 to 2,147,483,647 i.e. -231 to 231 -1. int is generally used as the
default data type for integer values unless there is a concern about memory.
Default value stored in int variable is 0.
Ex: int a = 100000, int b = -200000
Long: Long data type is a 64-bit signed integer number. The negative numbers
are expressed in two‘s complement form. The range accepted by long is
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 i.e. -263 to 263 -1. This
type is used when a wider range than int is needed. Default value stored in
long variable is 0.
Ex: long a = 100000L, long b = -200000L
Floating point data types: Floating point data types are used to store numbers
that have a fractional part. Floating point data types are classified into two
types. They are
1. float
2. double
float: float data type is a single-precision 32-bit floating point number. float is
mainly used to save memory in large arrays of floating point numbers. Default
value stored in float variable is 0.0
Ex: float f1 = 234.5f
double: double data type is a double-precision 64-bit floating point number.
This data type is generally used as the default data type for fractional numbers.
Default value stored in double variable is 0.0
Ex: double d1 = 123.4
Non-Numeric data types: In Java, two of the eight primitive data types are
non-numeric types. Non-Numeric data types are classified into two types. They
are
1. char data types
2. boolean data types
char: char data type is a single 16-bit Unicode character. The range accepted
by char is 0 to 65,535 i.e. 0 to 216 -1. Char data type is used to store any
character.
Ex: char letterA = 'A'
boolean: boolean data type represents one bit of information. There are only
two possible values i.e. true and false. This data type is used for simple flags
that track true/false conditions. Default value is false
Ex: boolean found = true
Non-Primitive Data Types:- The non-primitive data types are also commonly
referred as derived data types. Non-Primitive data types are classified into
three types. They are
1. Classes
2. Arrays
3. Interfaces
Classes: Class is an encapsulation of data along with its method. It is a user
defined data type. It acts as an template for creating objects.
Arrays: An array is a group of similar data items referred to by a common
name.
Interfaces: Interfaces are syntactically similar to classes, but they lack in
instance variables, and their methods are declared without any body.
Keywords: Keywords are the reserved words of the language. They have to be
used for the specified purpose only. There are 50 keywords currently defined in
the Java language as given in the table below. These keywords cannot be used
as names for a variable, class, or method.
Literals: Literal is a constant value in Java. Literal can be any number, text, or
other information that represents a value. Depending on the value the literals
are classified into 4 types. They are
1. Integer Literal
2. Floating-Point Literals
3. Character Literals
4. String Literals
Integer Literals: Any whole number is an integer literal. Examples are 1, 2, 3,
and 42. These are all decimal values, meaning they are describing a base 10
number. There are two other bases which can be used in integer literals, octal
(base eight) and hexadecimal (base 16). Octal values are denoted in Java by a
leading zero. Normal decimal numbers cannot have a leading zero. Thus, the
valid value 09 will produce an error from the compiler, since 9 is outside of
octal‘s 0 to 7 range. A more common base for numbers used by programmers
is hexadecimal. A hexadecimal constant with a leading zero-x, (0x or 0X). The
range of a hexadecimal digit is 0 to 15, so A through F (or a through f ) are
substituted for 10 through 15.
Floating-Point Literals: Floating-point numbers represent decimal values with a
fractional component. They can be expressed in either standard or scientific
Boolean Logical Operators: Boolean Logical operators are the operators which
take Boolean values as the input and produces Boolean values as the output.
The following table lists the Boolean logical operators:
forms, rather than the | and & forms of these operators, Java will not bother to
evaluate the right-hand operand when the outcome of the expression can be
determined by the left operand alone. This is very useful when the right-hand
operand depends on the value of the left one in order to function properly.
Ex: if (denom != 0 && num / denom > 10)
Since the short-circuit form of AND (&&) is used, there is no risk of causing a
run-time exception when denom is zero. If this line of code were written using
the single & version of AND, both sides would be evaluated, causing a run-
time exception when denom is zero.
Ex: if(c==1 & e++ < 100) d = 100;
Here, using a single & ensures that the increment operation will be applied to
e whether c is equal to 1 or not.
The Assignment Operator: The assignment operator is the single equal sign, =.
It has this general form:
var = expression;
Here, the type of var must be compatible with the type of expression. The
assignment operator allows to create a chain of assignments.
Ex: int x, y, z;
x = y = z = 100; // set x, y, and z to 100
This fragment sets the variables x, y, and z to 100 using a single statement. This
works because the = is an operator that yields the value of the right-hand
expression. Thus, the value of z = 100 is 100, which is then assigned to y, which
in turn is assigned to x. Using a ―chain of assignment‖ is an easy way to set a
group of variables to a common value.
The ? Operator: Java includes a special ternary (three-way) operator that can
replace certain types of if-then-else statements. ?. is the ternary operator and
its general form is
expression1 ? expression2 : expression3
Here, expression1 can be any expression that evaluates to a boolean value. If
expression1 is true, then expression2 is evaluated; otherwise, expression3 is
evaluated. Both expression2 and expression3 are required to return the same
type, which can‘t be void.
Ex: ratio = denom == 0 ? 0 : num / denom;
block, and continue labels must be on an iteration statement. The three types
of Jump statement are break, continue and return.
if(condition)
{
statement-block;
}
next-statement;
if(condition1)
{
if(condition2)
{
statement1-block;
}
else
{
statement2-block;
}
}
else
{
statement3-block;
}
next-statement;
max = num2;
else
max = num3;
System.out.println(―Maximum number is "+max);
}
}
else-if ladder : When one if statement is added in the else part of another if
statement then it is called as else – if ladder statement.
Syntax: Flowchart:
if(condition1)
statement1-block;
else if(condition2)
statement2-block;
else if(condition3)
statement3-block;
statement4-block;
next-statement;
r1=-b/(2*a);
System.out.println("Roots are Real and Equal");
System.out.println("Root1=Root2="+r1);
}
else
{
double sqrtd=Math.sqrt(d);
r1=(-b+sqrtd)/(2*a);
r2=(-b-sqrtd)/(2*a);
System.out.println("Roots are Real and Equal");
System.out.println("Root1= "+r1+" Root2= "+r2);
}
}
}
}
public class Quad
{
public static void main(String[] args)
{
float n1,n2, n3 ;
Scanner input = new Scanner(System.in);
System.out.print("Enter the values of Quadratic Equation: ");
n1=input.nextFloat();
n2=input.nextFloat();
n3=input.nextFloat();
QRoots qr = new QRoots();
qr.roots(n1, n2, n3);
}
}
switch statement: The switch statement is a multiway branch statement. It
provides an easy way to select one of the option among several options. It
often provides a better alternative than a large series of if-else-if statements.
Here is the general form of a switch statement:
switch (expression)
{
case value1: statement1-block;
break;
case value2: statement2-block;
break;
...
case valueN: statementN-block;
break;
default: defaultstatement-block;
}
The expression must be of type byte, short, int, or char. Each of the values
specified in the case statements must be of a type compatible with the
expression. Each case value must be a unique literal that is, it must be a
constant, not a variable. Duplicate case values are not allowed.
The switch statement works like this: The value of the expression is
compared with each of the literal values in the case statements. If a match is
found, the code sequence following that case statement is executed. If none of
the constants matches the value of the expression, then the default statement
is executed. However, the default statement is optional. If no case matches and
no default is present, then no further action is taken. The break statement is
used inside the switch to terminate a statement sequence. When a break
statement is encountered, execution branches to the first line of code that
follows the entire switch statement. This has the effect of ―jumping out‖ of the
switch.
// Program to read day numbers and print name of the day using switch
statement
import java.util.Scanner;
public class DayName
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
System.out.println("Enter the day number:");
int dayno=input.nextInt();
switch(dayno)
{
case 1: System.out.println(dayno+"day in the week is Monday");
break;
case 2: System.out.println(dayno+"day in the week is Tuesday");
break;
case 3: System.out.println(dayno+"day in the week is Wednesday");
break;
case 4: System.out.println(dayno+"day in the week is Thursday");
break;
case 5: System.out.println(dayno+"day in the week is Friday");
break;
case 6: System.out.println(dayno+"day in the week is Saturday");
break;
case 7: System.out.println(dayno+"day in the week is Sunday");
break;
default :System.out.println(dayno+"is an Invalid Day Number");
}
}
}
Iteration Statements: Iteration Statement repeats set of instruction until the
condition for termination is met. These statements appear in the source code
only once, but it execute many times. Such kinds of statements are also called
as loops. Iteration Statement in Java are mainly of three types
1. 'while' Statement
2. 'do while' Statement
3. 'for' Statement
while Statement: The while loop is an entry controlled loop. It tests the
condition before executing the loop body. The condition can be any Boolean
expression. The body of the loop will be executed as long as the conditional
expression is true. When condition becomes false, control passes to the next
line of code immediately following the loop. The curly braces are unnecessary
if only a single statement is being repeated. The general form of the while
statement is
while(condition)
{
// body of loop
}
// Program to search an element using Binary Search
import java.util.Scanner;
public class BinarySearch
{
}
if (ele == number[lower])
System.out.println(ele + "is found in the list " + lower
+ "position");
else
System.out.println(ele + "is not found in the list");
}
}
do-while: The do-while loop is an exit controlled loop. The do-while loop
always executes its body at least once, because its conditional expression is at
the bottom of the loop. Its general form is
do
{
// body of loop
} while (condition);
Each iteration of the do-while loop first executes the body of the loop and
then evaluates the conditional expression. If this expression is true, the loop
will repeat. Otherwise, the loop terminates.
// Program to print the reverse of a given number
import java.util.Scanner;
class RevNum
{
public static void main(String args[])
{
int num,rev,rem ;
Scanner input = new Scanner(System.in);
System.out.print("Enter any integer number :");
num=input.nextInt();
int num1=num;
rev=0;
do
{
rem = num % 10;
rev=rev*10+rem;
num = num /10;
}while(num!=0);
System.out.print("The reverse number of " + num1+"is "+rev);
}
}
for: Beginning with JDK 5, there are two forms of the for loop. The first is the
traditional form that has been in use since the original version of Java. The
second is the new ―for-each‖ form.
For loop: For loop executes group of Java statements as long as the boolean
condition evaluates to true. For loop combines three elements which we
generally use: initialization statement, boolean expression and increment or
decrement statement. Here is the general form of the traditional for statement:
for(initialization; condition; iteration)
{
// body
}
If only one statement is being repeated, there is no need for the curly braces.
The for loop operates as follows. When the loop first starts, the initialization
portion of the loop is executed. Generally, this is an expression that sets the
value of the loop control variable, which acts as a counter that controls the
loop. It is important to understand that the initialization expression is only
executed once. Next, condition is evaluated. This must be a Boolean
expression. It usually tests the loop control variable against a target value. If
this expression is true, then the body of the loop is executed. If it is false, the
loop terminates. Next, the iteration portion of the loop is executed. This is
usually an expression that increments or decrements the loop control variable.
The loop then iterates, first evaluating the conditional expression, then
executing the body of the loop, and then executing the iteration expression
with each pass. This process repeats until the controlling expression is false.
// Program to print factorial of a number
import java.util.Scanner;
class ReturnFact
{
}
}
Nested Loops: Like all other programming languages, Java allows loops to be
nested. That is, one loop may be inside another. For example, here is a
program that nests for loops:
// Program to sort a given list of numbers
import java.util.*;
public class Sort
{
public static void main(String args[])
{
int n;
Scanner input = new Scanner(System.in);
System.out.println("Enter how many numbers: ");
n=input.nextInt();
System.out.println("Enter "+n+" numbers one by one ");
float number[]= new float[n];
for(int i=0;i<n;i++)
number[i]=input.nextFloat();
for(int i=0;i<n-1;i++)
for(int j=0;j<n-i-1;j++)
if(number[j]>number[j+1])
{
float temp=number[j];
number[j]=number[j+1];
number[j+1]=temp;
}
System.out.println("sorted list ia as follows");
for(int i=0;i<n;i++)
System.out.print(" "+number[i]);
}
}
Jump Statements: Java supports three jump statements: break, continue, and
return. These statements transfer control of execution to another part of the
program.
break: In Java, the break statement has three uses. First, as you have seen, it
terminates a statement sequence in a switch statement. Second, it can be used
to exit a loop. Third, it can be used as a ―civilized‖ form of goto. The last two
uses are explained here.
int i,j,n;
Scanner input = new Scanner(System.in);
System.out.println("Enter how many rows:");
n=input.nextInt();
outer:for(i=1;;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(" * ");
if(i==n)
break outer;
}
System.out.println();
}
}
}
Continue: A continue statement causes control to be transferred directly to the
conditional expression that controls the loop.
// Program to print the squareroot of positive numbers
import java.util.Scanner;
class ContSqrt
{
public static void main(String args[])
{
int i;
float num[] = new float[10];
Scanner input = new Scanner(System.in);
System.out.println("Enter 10 numbers to find sqrt:");
for(i=0; i<10;i++)
num[i]=input.nextFloat();
System.out.println("------------------------------");
System.out.println("Number\tSqureroot");
System.out.println("------------------------------");
for(float x: num)
{
if(x>=0)
System.out.println(x+"\t"+Math.sqrt(x));
else
continue;
}
System.out.println("------------------------------");
}
}
Labelled continue: Continue may also specify a label to describe which
enclosing loop to continue.
// Program to print triangle of stars
import java.util.Scanner;
class ContStar
{
public static void main(String args[])
{
int i,j,n;
Scanner input = new Scanner(System.in);
System.out.println("Enter how many rows:");
n=input.nextInt();
outer: for(i=1;i<=n;i++)
{
System.out.println();
for(j=1;;j++)
{
System.out.print(" * ");
if(j==i)
continue outer;
}
}
}
}
Return: The last control statement is return. The return statement is used to
explicitly return from a method. That is, it causes program control to transfer
back to the caller of the method.
// Program to print factorial of a number
import java.util.Scanner;
class ReturnFact
{
public long fact(int n)
{
int i ;
long f=1;
for(i=1;i<=n;i++)
f*=i;
return f;
}
}
}
Methods: Classes usually consist of two things. They are instance variables and
methods. The general form of a method is :
type name(parameter-list)
{
// body of method
}
Here, type specifies the type of data returned by the method. This can be any
valid type, including class types that are already created. If the method does
not return a value, its return type must be void. The name of the method can
be any legal identifier other than those already used by other items within the
current scope. The parameter-list is a sequence of type and identifier pairs
separated by commas. Parameters are essentially variables that receive the
value of the arguments passed to the method when it is called. If the method
has no parameters, then the parameter list will be empty.
// Program to use class that contains data members and methods
import java.util.*;
class StudDet
{
private int studno;
private String name;
void getDet()
{
Scanner input = new Scanner(System.in);
System.out.println("Enter Student no and name : ");
studno = input.nextInt();
name = input.next();
}
void printDet()
{
System.out.println("The Student Details are as follows : ");
System.out.println("Roll Number : "+studno);
System.out.println("Name : "+name);
}
}
public class Stud
{
public static void main(String args[])
{
StudDet s1=new StudDet();
s1.getDet();
s1.printDet();
}
}
Returning a Value: Methods can return value to the calling function. The
general form of the return statement:
return value;
Here, value is the value returned.
// Program to use class which contains a method which returns value
import java.util.*;
}
public static void main(String args[])
{
StudMarks s1=new StudMarks();
s1.getDet();
s1.printDet();
System.out.println("Total : "+s1.calTotal());
}
}
Adding a Method That Takes Parameters: While some methods don‘t need
parameters, most do. Parameters allow a method to be generalized. That is, a
parameterized method can operate on a variety of data and/or be used in a
number of slightly different situations. To
// Program to use class which contains methods that take parameters
import java.util.*;
class StudDet
{
private int studno;
private String name;
void setDet(int rno, String sname)
{
studno = rno;
name = sname;
}
void printDet()
{
System.out.println("The Student Details are as follows : ");
System.out.println("Roll Number : "+studno);
System.out.println("Name : "+name);
}
}
public class Stud
{
public static void main(String args[])
{
int rno;
String sname;
StudDet s1=new StudDet();
Scanner input = new Scanner(System.in);
System.out.println("Enter Student no and name : ");
rno = input.nextInt();
sname = input.next();
s1.setDet(rno,sname);
s1.printDet();
}
}
Argument Passing: In general, there are two ways to pass argument to a
method. They are
1. call-by-value
2. call-by-reference
The first way is call-by-value. This approach copies the value of an argument
into the formal parameter of the method. Therefore, changes made to the
parameter in the called method have no effect on the argument in the calling
method. When you pass a primitive type to a method, it is call by value.
The second way an argument can be passed is call-by-reference. In this
approach, a reference to an argument (not the value of the argument) is
passed to the parameter. Inside the called method, this reference is used to
access the actual argument specified in the call. This means that changes made
to the parameter in the called method will affect the argument in the calling
method. When you pass objects to a method, it is call by reference.
// Program to demonstrate call by value technique.
import java.util.Scanner;
class Test
{
void swap(float i, float j)
{
float temp;
temp=i;
i=j;
j=temp;
}
}
class CallByValue
{
float a , b;
public static void main(String args[])
{
Test ob = new Test();
}
Constructor: A constructor is a special method that is used to initialize a newly
created object and is called just after the memory is allocated for the object. It
can be used to initialize the objects ,to required ,or default values at the time
of object creation. It is not mandatory for the coder to write a constructor for
the class
If no user defined constructor is provided for a class, compiler initializes
member variables to its default values.
numeric data types are set to 0
char data types are set to null character(‗\0‘)
reference variables are set to null
Rules for create a Java Constructor
1. It has the same name as the class
2. It should not return a value not even void
// Program using constructor with no arguments
import java.util.Scanner;
class StudDet1
{
private int studno;
private String name;
StudDet1()
{
Scanner input = new Scanner(System.in);
System.out.println("Enter Student no and name : ");
studno = input.nextInt();
name = input.next();
}
void printDet()
{
System.out.println("The Student Details are as follows : ");
System.out.println("Roll Number : "+studno);
System.out.println("Name : "+name);
}
}
public class StudentDetails
{
public static void main(String args[])
{
StudDet1 s1=new StudDet1();
s1.printDet();
}
}
Parameterized Constructors: The parameters can also be passed to
constructors.
// Program using parametrized constructor
import java.util.Scanner;
class StudDet12
{
private int studno;
private String name;
StudDet12(int sno1, String sname1)
{
studno = sno1;
name = sname1;
}
void printDet()
{
System.out.println("The Student Details are as follows : ");
System.out.println("Roll Number : "+studno);
System.out.println("Name : "+name);
}
}
public class StudentDetails1
{
public static void main(String args[])throws Exception
{
Scanner input = new Scanner(System.in);
System.out.println("Enter Student no and name : ");
int sno = input.nextInt();
String sname = input.next();
StudDet12 s1=new StudDet12(sno,sname);
s1.printDet();
}
}
this.studno = studno;
this.name = name;
cnt++;
}
void printDet()
{
System.out.println("The Student Details are as follows : ");
System.out.println("Roll Number : "+studno);
System.out.println("Name : "+name);
System.out.println("Number of Objects Created : "+cnt);
}
}
public class StudentStatic
{
public static void main(String args[])throws Exception
{
Scanner input = new Scanner(System.in);
System.out.println("Enter Student no and name : ");
int sno = input.nextInt();
String sname = input.next();
StudDet1234 s1=new StudDet1234(sno,sname);
s1.printDet();
System.out.println("Enter Student no and name : ");
sno = input.nextInt();
sname = input.next();
StudDet1234 s2=new StudDet1234(sno,sname);
s2.printDet();
}
}
Static Method:
It is a method which belongs to the class and not to the object(instance)
A static method can access only static data. It can not access non-static
data (instance variables)
A static method can call only other static methods and can not call a
non-static method from it.
A static method can be accessed directly by the class name and doesn‘t
need any object
Syntax : <class-name>.<method-name>
A static method cannot refer to "this" or "super" keywords in anyway
// Program using static variable and method
import java.util.Scanner;
class StudDet5
{
private int studno;
private String name;
static int cnt;
StudDet5(int studno, String name)
{
this.studno = studno;
this.name = name;
cnt++;
}
void printDet()
{
System.out.println("The Student Details are as follows : ");
System.out.println("Roll Number : "+studno);
System.out.println("Name : "+name);
}
static void printCnt()
{
System.out.println("Number of Objects Created : "+cnt);
}
}
public class StudentStaticM
{
public static void main(String args[])throws Exception
{
Scanner input = new Scanner(System.in);
System.out.println("Enter Student no and name : ");
int sno = input.nextInt();
String sname = input.next();
StudDet5 s1=new StudDet5(sno,sname);
s1.printDet();
System.out.println("Enter Student no and name : ");
sno = input.nextInt();
sname = input.next();
StudDet5 s2=new StudDet5(sno,sname);
s2.printDet();
StudDet5.printCnt();
}
}
Static Block: Static block is mostly used for changing the default values of
static variables. This block gets executed when the class is loaded in the
memory. A class can have multiple Static blocks, which will execute in the same
sequence in which they have been written into the program.
class StaticBlock
{
static int num;
static String mystr;
static
{
num = 97;
mystr = "Static Block in Java";
}
public static void main(String args[])
{
System.out.println("Value of num="+num);
System.out.println("Value of mystr="+mystr);
}
}
Java "THIS" Keyword: Sometimes a method will need to refer to the object
that invoked it. To allow this, Java defines the this keyword. this can be used
inside any method to refer to the current object. That is, this is always a
reference to the object on which the method was invoked. when a local
variable has the same name as an instance variable, the local variable hides the
instance variable. To avoid this problem this keyword can be used.
Keyword 'THIS' in Java is a reference variable that refers to the current object.
The various usage of keyword Java 'THIS' in Java is as per the below,
number[i] = input.nextFloat();
System.out.println("Enter the element to be searched : ");
ele = input.nextFloat();
int lower = 0;
int upper = n - 1;
int middle;
while (lower < upper)
{
middle = (lower + upper) / 2;
if (ele > number[middle])
lower = middle + 1;
else
upper = middle;
}
if (ele == number[lower])
System.out.println(ele + "is found at " + lower+ "position in the list");
else
System.out.println(ele + "is not found in the list");
}
}
Two-Dimensional Arrays: A two-dimensional array is an array of arrays that
contain similar data items. In two -dimensional array two subscripts are used
to refer an array element. The general form of a two-dimensional array
declaration is
Syntax: type var-name[ ][ ]=new type[ ][ ];
Ex: float a[][] = new float[3][3];
// Program to find the product of two matrices
import java.util.Scanner;
public class MatMul
{
public static void main(String args[])
{
int i,j,k,m, n,p,q;
Scanner input = new Scanner(System.in);
System.out.println("Enter the size of matrix A: ");
m = input.nextInt();
n=input.nextInt();
argument is the information that directly follows the program‘s name on the
command line when it is executed. To access the command-line arguments
inside a Java program is quite easy. They are stored as strings in a String array
passed to the args parameter of main( ). The first command-line argument is
stored at args[0], the second at args[1], and so on. All command-line
arguments are passed as strings and must be converted to numeric values for
calculation pupose.
// Program to get day number as command line argument and print dayname
public class CommandLine
{
public static void main(String args[])
{
int dayno=Integer.parseInt(args[0]);
switch(dayno)
{
case 1: System.out.println(dayno+"day in the week is Monday");
break;
case 2: System.out.println(dayno+"day in the week is Tuesday");
break;
case 3: System.out.println(dayno+"day in the week is Wednesday");
break;
case 4: System.out.println(dayno+"day in the week is Thursday");
break;
case 5: System.out.println(dayno+"day in the week is Friday");
break;
case 6: System.out.println(dayno+"day in the week is Saturday");
break;
case 7: System.out.println(dayno+"day in the week is Sunday");
break;
default :System.out.println(dayno+"is an Invalid Day Number");
}
}
}