JAVA
JAVA
REFERENCE https://www.javatpoint.com/java-reserved-keywords
PROGRAMS
1 Write a program to swap / exchange values of two variables -
a) Using 3rd variable b) Without using 3rd variable
2 Write a program to check if an Input character is an alphabet or not . If an alphabet , further check and
print if its upper case alphabet or lower case alphabet
3 Write a program to check and display if an Input character is alphanumeric character or a special character
4 Write a program to generate the reverse of a string and check if it is a Palindrome or not.
5 Write program for a SIMPLE CALCULATOR using switch case
LOOPS
6 WAP to print sum of all odd numbers and product of all even numbers from 1 to n (n is user input)(USE A
SINGLE LOOP )
7 Find sum of positive integers and sum of negative integers from n numbers entered by the user.
8 Find average of n numbers entered by the user
9 Find sum of odd numbers and sum of even numbers from n numbers entered by the user.
10 Process Result of n students ( Marks in 5 subjects to be taken as input and percentage obtained and grade
to be displayed)
11 Process Salary of n employees ( Basic Salary, DA, HRA to be taken as input and Net Salary to be
displayed)
12 Calculate and print a b
13 Write a program to find and print the average of given array elements.(Array of floating point values)
14 Print the series 1, 2, 4 , 7 ,11,16…….. till n terms (n is user input)
14 PROGRAM
int t=1;
for (int i=1:i<=n;++i)
{
print(t);
t=t+i;
}
QUESTIONS
1 Why is Java considered as an Object Oriented Programming language ? Write any 3 features of Java .
2 “Java can be used to write diverse applications”. Explain
3 Java is case sensitive language. Justify the statement.
4 Which component is used to compile, debug and execute java program? (JDK)
16 ________ statement allows to use a pre-built class and their associated methods from a package.
a)include b) import c)public d)extends
17 Write advantages of using comments in a Program? How can you write single line and multiline
comments in Java program?
18 Define Variable?
19 State True/ False
a)All variables must be declared and initialized before they are used .
b)Data type of a variable doesn’t tell the compiler about how much memory should be reserved for the
variable
c)While declaring a variable we may or may not tell the datatype of the variable
d) Its essential to initialize a variable whenever we declare it
20 What is meant by datatype? Describe the basic data types in Java. Make a table of Java primitive data
types (data type, type of values, size)
char String
29 Explain working of if-else statement. Write syntax of if-else statement (Conditional statements)
30 Explain working of switch case statement.Write syntax also.
31 Write advantages and limitations of switch case statement (compare with if else statement)
32 Differentiate between if else and switch case statements
33 Explain the significance of a) break b) default in switch case statement
41 Write Output
public static void main(String [] args)
{
int r=7, sum=0;
for (int i=1;i<=7;++i)
sum=sum+ ++r;
System.out.println(sum);
}
ANS 77
42 Write Output
public static void main(String [] args)
{
int c=1, b=6,a=0;
for (int i=1;i<=7;++i)
a=c* --b+6;
System.out.println(a);
}
ANS 5
SWITCH CASE
1 Give the output of the following code segment-
public class Main {
public static void main(String[] args) {
int day = 4;
switch (day)
{
default: System.out.println("Looking forward to the Weekend");
case 6: System.out.println("Today is Saturday");
break;
case 7:System.out.println("Today is Sunday");
break;
}
}
}
float a=1.0;
switch(a)
{
default : jTextField1.setText("transparent");
break;
case 0 : jTextField1.setText("Blue");
case 1 : jTextField1.setText("Red");
}
3 Rewrite the following program code using switch statement :
if (color == 10)
{ system.out.println("Red")
; }
else if (color == 20)
{
System.out.println ("Orange");}
else if (color == 30)
{
System.out.println ("Green");
}
else
{
System.out.println ("Invalid");
}
4 Rewrite following code using Switch case
char c=’a’;
if (c==’a’)
System.out.println(‘Autumn’);
else if (c==’w’)
System.out.println(‘Winter’);
else if (c==’r’)
System.out.println(‘Rainy’);
else if (c==’s’)
System.out.println(‘Summer’);
else
System.out.println(‘Invalid’);
switch(d)
{
case 1:
case 2:
case 3:
case 5:System.out.println(“WEEKDAY”);
break;
case 4:System.out.println(“HOLIDAY”);
break;
case 6:
case 7:System.out.println(“WEEKEND”);
break;
default:System.out.println(“INVALID”);
break;