Week - 7: Problems Based On If statement/Looping/Array/Strings in Java
Week - 7: Problems Based On If statement/Looping/Array/Strings in Java
else
last_ar = mid - 1;
Result:
2# Write a java program to arrange the elements of an array in ascending order(Sorting).
Source Code:
public class Sorting {
System.out.print("\nBefore sorting the array is: {11, 585, 177, 222, 9}");
int temp;
for (int i = 0; i < len - 1; i++)
for (int j = 0; j < len - 1 - i; j++)
if (ar[j] > ar[j + 1])
{
temp = ar[j];
ar[j] = ar[j + 1];
ar[j + 1] = temp;
}
Result:
3# Write a java program to store 'Java is awesome' in a string and display it.
Source Code:
public class String_Print {
Result:
Source Code:
import java.util.Scanner;
int check = 0;
for (int i = 0; i < str.length()/2 ; i++)
{
if (str.charAt(i) != str.charAt(str.length() - 1- i))
{
System.out.println("\n\"" + str + "\" is not a palindrome.");
check = 1;
break;
}
}
if (check == 0)
System.out.println("\n\"" + str + "\" is a palindrome.");
}
}
Result:
Source Code:
<html>
<head>
<title>Week 7(1) Image Table</title>
</head>
<body>
<table>
<tr>
<td><img src="Window.jpg"></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td><img src="Window.jpg"></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td><img src="Window.jpg"></td>
</tr>
</table>
</body>
</html>
Result:
Source Code:
<html>
<head>
<title>Week 7(2) Table</title>
</head>
<body>
<table border="1">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td rowspan="2" colspan="2"><img src="Window.jpg"></td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
</tr>
<tr>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
</tr>
</table>
</body>
</html>
Result:
Week - 8
Problems Based on Object/Class/Constructor in Java
1# Create a class FRUIT which has data members color, taste and price. Also create a
method display() which will print values of FRUIT object. Create three objects of FRUIT
class and call their display() methods.
Souce Code:
public class FRUIT {
String colour;
String taste;
double price;
void display()
{
System.out.println("Colour: " + colour);
System.out.println("Taste: " + taste);
System.out.println("Price: " + price);
}
apple.colour = "Red";
apple.taste = "Sweet";
apple.price = 60;
orange.colour = "Orange";
orange.taste = "Sweet & Sour";
orange.price = 35;
banana.colour = "Yellow";
banana.taste = "Sweet";
banana.price = 25;
System.out.println("Apple:-");
apple.display();
System.out.println("\nOrange:-");
orange.display();
System.out.println("\nBanana:-");
banana.display();
}
}
Result:
2# Create a class FRUIT which has data members color, taste and price. It has a method
setDetails() which will set the values of color, taste and price. Also create a method
display() which will print values of FRUIT object.
Source Code:
public class FRUIT {
String colour;
String taste;
double price;
void display()
{
System.out.println("Colour: " + colour);
System.out.println("Taste: " + taste);
System.out.println("Price: " + price);
}
System.out.println("Apple:-");
apple.display();
System.out.println("\nOrange:-");
orange.display();
System.out.println("\nBanana:-");
banana.display();
}
}
Result:
3# In previous question, set the values of using color, taste and price using Constructor.
Source Code:
public class FRUIT {
String colour;
String taste;
double price;
void display()
{
System.out.println("Colour: " + colour);
System.out.println("Taste: " + taste);
System.out.println("Price: " + price);
}
System.out.println("Apple:-");
apple.display();
System.out.println("\nOrange:-");
orange.display();
System.out.println("\nBanana:-");
banana.display();
}
}
Result:
Source Code:
public class FRUIT {
FRUIT(double price_)
{
price = price_;
}
void display()
{
System.out.println("Colour: " + colour);
System.out.println("Taste: " + taste);
System.out.println("Price: " + price);
}
System.out.println("Mango:-");
mango.display();
System.out.println("\nOrange:-");
orange.display();
System.out.println("\nPomegranate:-");
pomegranate.display();
}
}
Result:
Source Code:
public class FRUIT {
FRUIT(double price_)
{
price = price_;
}
void display()
{
System.out.println("Colour: " + this.colour);
System.out.println("Taste: " + this.taste);
System.out.println("Price: " + this.price);
}
System.out.println("Mango:-");
mango.display();
System.out.println("\nOrange:-");
orange.display();
System.out.println("\nPomegranate:-");
pomegranate.display();
}
}
Result:
Problems Based on HTML:
1# Write an HTML code to develop a Web page having two frames that divide the Web
page into two equal rows and then divide the second row into two equal columns, then fill
each frame with a different background colour.
Source Code:
<!DOCTYPE html>
<html>
<head>
<title>Week 8 Frames</title>
</head>
<frameset rows="50%, 50%">
<frame src = "Frame1.html">
<frameset cols="50%, 50%">
<frame src="Frame2(a).html">
<frame src="Frame2(b).html">
</frameset>
</frameset>
</html>
Result: