Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
59 views

JAVA

JAVA assignment to study IT code 802 class 12 :)

Uploaded by

Geet
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

JAVA

JAVA assignment to study IT code 802 class 12 :)

Uploaded by

Geet
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

DAV PUBLIC .

SCHOOL , SECTOR 14,GURUGRAM


XII, INFORMATION TECHNOLOGY
ASSIGNMENT -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)

5 a) Explain the role of Scanner Class


b)How to convert integer to string ?
c)How to convert string to integer?
d)How to convert string to float?
e)How to convert string to double ?

f)Explain parseFloat(), parseDouble() ,parseInt() methods

g) method takes a String as parameter and returns the equivalent integer.


h) ____________ are programmers who code in high level languages.(Application Programmers)
6 Define Compiler OR Explain role of a compiler .
7 What is Bytecode?
8 What is the role of IDE?
9 Explain how Java is Platform independent . What is JVM?
10 Define Program
11 Define a) Method b) Package
12 Define main() method
13________is a special method that every Java application must have.When we run a program , the
statements in this method are the first to be executed.
14_______ is a group of related classes.
15_________is a group of statements written to perform a specific task.

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)

21 I Compare the following datatypes in Java:


a)double and float
a) long and float
c)char and String

char String

primitive data type in Java is a class in java

represents a single character can have zero or more characters.


is an array of chars

defined using single quote '’ using double quotes (")

d) int and double


e) short and int
f) int and long

II The size of double datatype in java is bit.


III In Java, Size of Primitive data type ‘boolean’ is ________bits

22 Which of the following are Java Keywords ?


a) public b) static c) class d) boolean

23 Write any 4 rules of naming variables?

24 Identify invalid variable names from following


a) int$ b)int c) 1comm d) comm1 e) comm_1 f) sale 12
g) break h) while i) my_string_1 j) mystring1 k) _mystring1

25 Write and explain any two Relational operators in Java.


26 Write and explain any two Logical operators in Java.

27 Explain operator ++ increment operator , -- decrement operator


28 Write OUTPUT - System.out.println(10/3); // 3
Write OUTPUT - System.out.println(10.0 /3); // 3.33
NOTE - Division operator returns integer quotient when both operands are int

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

34 Explain the significance of a) break b) continue in Loops

35 Differentiate between While loop and do-while Loop


36 Explain the working of for loop.

37 What is an Infinite loop? Write an example(Java code) of the same .


38 What is an Empty loop? Write an example(Java code) of the same .
39 a) _____________ loop runs at least once.
b) State True / False:
We can write multiple items in all three parts (Initialization part, update expression, test condition) of a for
loop , using comma as a separator .

40 Predict the output of the following code , if N=19 is passed as an argument to it

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;

}
}
}

2 Identify errors in the following code and rewrite corrected code

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’);

5 Rewrite following code using if -else if- else


Following is the code to print “working day“ or “holiday” or “weekend” for one week of a given month
Suppose 4 th is Holiday , 1,2,3,5 are weekdays and 6,7 are weekend

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;

You might also like