Академический Документы
Профессиональный Документы
Культура Документы
x++
x--
++x
--x
Ans1
4
6
int sum1 = 3;
sum1++;
jTextField1.setText(""+sum1);
++sum1;
jTextField2.setText(""+(++sum1));
Ques 2: Using variables to hold
incremented or decremented value
int sum1 = 3;
int n1=sum1++;
jTextField1.setText(""+n1);
int n2=++sum1;
jTextField2.setText(""+(++n2));
Ans2
3
6
3
Pre increment
Output question 3
// value of for loop will be incremented
or decremented once loop gets
completed.
int x,y=0;
for(x=1;x<=5;++x)
{
System.out.println(" x is after loop"
+" "+x);
y=++x;
System.out.println(" y=++x x is "
+" "+x);
System.out.println(" y=++x " +"
"+y);
--y;
System.out.println(" - -y " +" "+y);
}
System.out.println("x is"+x);
System.out.println(y);
Ans 3 :
x is after loop 1
y=++x x is 2
y=++x 2
- -y 1
x is after loop 3
y=++x x is 4
y=++x 4
- -y 3
x is after loop 5
y=++x x is 6
y=++x 6
- -y 5
x is7
5
5
Post increment
Ques 4
int x,y=0;
for(x=1;x<=5;x++)
{
System.out.println(" x is after
loop" +" "+x);
y=x++;
System.out.println(" y=x++ "
+" "+y);
-- y;
System.out.println(" - -y " +"
"+y);
}
System.out.println("x is"+x);
System.out.println(y);
Ans 4:
x is after loop 1
y=x++ 1
- -y 0
x is after loop 3
y=x++ 3
- -y 2
x is after loop 5
y=x++ 5
- -y 4
x is7
4
Q5
int sum1 = 3;
int sum2=sum1++ +2;
jTextField1.setText(""+sum2);
++sum1;
jTextField2.setText(""+(++sum1));
Ans5
5
6
Q6
int val1=5,val2=10;
for(int i=1;i<=3;i++)
{
system.out.println( +val1++ +, +
--val2);
system.out.println( +val2-- +, + +
+val1);
10
Ans5
5 ,9
9,7
7,7
7,9
9,5
5,11
11
substring in java
Output question
String str = "life is beautiful;
String val1 = str.substring(0,10);
String val2 = str.substring(0,6);
String val3 = str.substring(8);
String v3=str.substring(0);
String v4=str.substring(1);
System.out.println("substr at 0,10 position is" +"
"+val1);
System.out.println("substr at o ,6 is" +" "+val2);
System.out.println("substr at 8 is" +" "+val3);
System.out.println("substr at o is" +" "+v3);
System.out.println("substr at 1 is" +" "+v4);
0
1
0
1
1
1
2
1
3
1
4
1
5
1
6
12
1
7
substring in java
Ans
substr
substr
substr
substr
substr
at
at
at
at
at
13
Nested loop
The placing of one loop inside the body of another loop is
callednesting.
14
Screen
int num2
int num1
0
0
1
2
3end loop
0
1
2
3end loop
0
1
2
3end loop
0
15
Nested loop
Ans :
Ques
for(int i=1;i<=4;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(" "+i);
1
22
333
4444
}
System.out.println();
}
16
Nested loop
Ans :
Ques
for(int i=1;i<=4;i++)
{
for(int j=1;j<=4;j++)
{
System.out.print(" "+i);
1
2
3
4
1
2
3
4
1
2
3
4
1
2
3
4
}
System.out.println();
}
17
Nested loop
Ans :
Ques
for(int i=1;i<=4;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(" "+j);
1
12
123
1234
}
System.out.println();
}
18
Nested loop
Ans :
Ques
for(int i=1;i<=4;i++)
{
for(int j=4;j>=i;j--)
{
System.out.print(" "+j);
4321
432
43
4
}
System.out.println();
}
19
Nested loop
Ques TRY YOURSELF
for(int i=2;i<=5;i++)
{
System.out.print(i+ "=>");
for(int j=1;j<=3;j++)
{
System.out.print(i*j +",");
}
System.out.println();
}
20
Nested loop
Ans :
2=>2,4,6,
3=>3,6,9,
4=>4,8,12,
5=>5,10,15,
21
22
Ans 6:
1+2+4+=7
23
Q7
int a=10;
int b=12;
int x=5;
int y=6;
while (a<=b)
{
if (a%2==0)
{
x=x + y;
a=a+1;
}
else
{
x=x-y;
a=a+1; }
System.out.println(x);
}
24
Ans.
11
5
11
25
26
JUMP Statement
(i) break : The break is used to break from an enclosing
do,whilefor,or switch statement.
Syntax:
break;
()A break statement skips the rest of the loop and jumps
over to the statement following the loop.
()If a break statement appers in a nested loop , then it
causes an exit from only the very loop it appears in.
27
break statement
int i ,c;
int a=Integer.parseInt(jTextField1.getText());
int b=Integer.parseInt(jTextField2.getText());
for(i=0;i<20;i++)
{
if(b==0)
break;
else
c=a/b;
System.out.println("Quotient ="+c);
}
28
Jump Statement
Syntax:
continue;
For the for loop continue causes the nex iteration by updating the
variable and then causing the test expressions evaluation .
For the while and do while loops , the program control passes to the
conditional tests.
29
int i ,c;
int a=Integer.parseInt(jTextField1.getText());
int b=Integer.parseInt(jTextField2.getText());
for(i=0;i<20;i++)
{
if(b==0)
{
System.out.println("the denominator can't be zero enter again");
continue;
}
else
{ c=a/b;
System.out.println("Quotient ="+c);
}
}
System.out.println("code over!");
30
Jump Statement
(iii) return : Return is used to return
value from the method
Syntax:
Return <value>;
31
To be continued
RDBMS MYSQL
Constraints
Web applications <HREF> , <A>
tag
32
Web Application
33
Hyperlink
34
Hyperlink
<html>
<head>
<title> web1 </title>
</head>
<body>
<!webpage>
<a href="d:\hills.jpg">click </a>
0<sub>2 </sub>
z<sup>2</sup>
</body>
</html>
35
<html>
<head>
<title> web1 </title>
</head>
<body link="green" alink="red" vlink="blue">
<!webpage>
<a href="d:\hills.jpg">click </a>
0<sub>2 </sub>
z<sup>2</sup>
</body>
</html>
37
38
39
RDBMS
40
41
42
SQL Constraints
Primary Key :No two rows of a table can have the same primary.
If in any situation you need to have two primary key , key
If you
declare two primary key in the table in the following way
CREATE TABLE bills
(Order_Num INT(4) PRIMARY KEY,
cust_code VARCHAR(4) PRIMARY KEY,
bill_Date DATE, Bill_Amt DECIMAL(8,2));
it will not accept. It will give error as a table can have at most one
primary
So you need to declare combination of columns a primary
key
CREATE TABLE bills
(Order_Num INT(4), cust_code VARCHAR(4),
bill_Date date, Bill_Amt DECIMAL(8,2),
PRIMARY KEY(Order_Num, cust_code));
44
SQL Constraints
Primary Key :No two rows of a table can have the same primary.
If in any situation you need to have two primary key , key
If you
declare two primary key in the table in the following way
CREATE TABLE bills
(Order_Num INT(4) PRIMARY KEY,
cust_code VARCHAR(4) PRIMARY KEY,
bill_Date DATE, Bill_Amt DECIMAL(8,2));
it will not accept. It will give error as a table can have at most one
primary
So you need to declare combination of columns a primary
key
CREATE TABLE bills
(Order_Num INT(4), cust_code VARCHAR(4),
bill_Date date, Bill_Amt DECIMAL(8,2),
PRIMARY KEY(Order_Num, cust_code));
45
Suppose you want to delete primary key and want to set new set of
column as primary key then
ALTER TABLE Shoes DROP PRIMARY KEY;
ALTER TABLE Shoe ADD PRIMARY KEY (Name, Size);
UNIQUE constraint
TheUNIQUEconstraint ensures, that all data are unique in a column.
47
ENUM constraint
AnENUMis a string object with a value chosen from a list of permitted values.
They are enumerated explicitly in the column specification at table creation
time
48
SET constraint
A SET can have zero or more values. Each of the values must be chosen from a
list of permitted values. It is different from theENUMconstraint, where you
can have only one distinct value from the list of permitted values.
49
HAVING
Clause
50
Extra
51