Professional Documents
Culture Documents
11
12 Java program to calculate the simple interest
1
SOLUTIONS
import java.util.Scanner;
public class AddTwoNumbers2 {
sc.close();
sum = num1 + num2;
System.out.println("Sum of these numbers: "+sum);
}
}
Output:
Enter First Number:
121
Enter Second Number:
19
Sum of these numbers: 140
2
2. Java program to calculate the simple interest
import java.util.Scanner;
public class JavaExample
{
public static void main(String args[])
{
float p, r, t, sinterest;
Scanner scan = new Scanner(System.in);
System.out.print("Enter the Principal : ");
p = scan.nextFloat();
System.out.print("Enter the Rate of interest : ");
r = scan.nextFloat();
System.out.print("Enter the Time period : ");
t = scan.nextFloat();
scan.close();
sinterest = (p * r * t) / 100;
System.out.print("Simple Interest is: " +sinterest);
}
}
Output:
contpara(int a,int b)
3
{
Output:
4
}
}
class B2 extends Base
{
void type()
{
System.out.println("This is Class B2");
}
}
class java13
{
public static void main(String args[])
{
B1 b1 = new B1();
B2 b2 = new B2();
b1.type();
b2.type();
}
}
Output:
This is Class B1
This is Class B2
import java.util.Vector;
5
v.add("C");
v.add("C++");
v.add("JAVA");
v.add("J2EE");
System.out.println("initially the vector contents:" +v.toString());
System.out.println("the last element:" +v.lastElement());
System.out.println("the element at 2nd position:" +v.elementAt(2));
v.insertElementAt("VB",1);
v.insertElementAt("#c",0);
System.out.println("after inserting the vector contents:"
+v.toString());
v.removeElementAt(3);
System.out.println("after removing the element(3)- the contents:"
+v.toString());
v.setElementAt("C++", 1);
v.remove("VB");
System.out.println("after remove (VB) -the vector contents:"
+v.toString());
Output:
6
String str1="12345";
int num2=Integer.parseInt(str1);
System.out.println(" the value of num 2="+num2);
System.out.println(" the string value of i1="+i1.toString());
System.out.println(" the string value of i2="+i2.toString());
}
}
Output:
The primitive value of i1=100
The primitive value of i2=200
the value of num 2=12345
the string value of i1=100
the string value of i2=200
System.out.println("Thread is running");
7
t.start();
Output:
Thread is running
import java.awt.*;
import java.applet.*;
g.setColor(Color.red);
Output:
8
9. Write a java program to implement Graphics Program to Draw
RECTANGLE.
import java.awt.*;
import java.applet.*;
Output:
9
10. Write a java program to implement Graphics Program to Draw Barchart.
import java.awt.Graphics;
public class Barchart extends java.applet.Applet {
public void paint(Graphics g){
String year[]={"2006", "2007", "2008", "2009", "2010"};
int amount[]={120,140,135,150,170};
for(int i=0;i<5;i++){
g.drawString(year[i], 20, i*50+30);
g.fillRect(50, i*50+10, amount[i], 40);
Output:
10