Java Progrms
Java Progrms
Package squareroot;
Public class squareroot
{
public static void main(String[] args) {
double x = 64;
double y;
y=Math.sqrt(x);
System.out.println("y="+y);
}
2.Code execute and debug that uses different types of variables And data
types:
package variables;
}
package variables;
}
3 (A)code ,execute and debug programs that uses different types of
constructors
package student;
System.out.println(name+"\t"+regno+"\t"+marks1+"\t"+marks2+"\t"+mar
ks3);
}
}
package student;
public class studentdemo {
}
c.to perform Autoboxing and Unboxing:
package hello;
Unboxing:
package unboxing;
public class hello {
}
5. Code execute and debug programs that uses different control statements:
}
c. Write a java program to check for vowel or consonant:
package vowel;
public class vo {
D Write a java program to find sum of first 20 natural number using for
loop:
}
F Write the program to display 1 to 10 natural numbers (do while):
}
6 CODE , EXECUTE AND DEBUG PROGRAMS
A)THAT USES ENCAPSULATION CONCEPT
System.out.print("Name:"+encap.getName()+"\nAge:"+encap.getAge());
}
}
b) define class and implement like simple calculator or text processing
complie with SRP.
public class calculator {
addition a = new addition();
subtraction s = new subtraction();
multiplication m = new multiplication();
division d = new division();
}
}
public class addition {
int res;
void add(int a, int b) {
res = a + b;
System.out.println("Addition of two numbers ="+res);
}
}
public class subtraction {
int res;
void sub(int a, int b) {
res = a - b;
System.out.println("Subtraction of two numbers ="+ res);
}
public class multiplication {
int res;
void mul(int a, int b) {
res = a * b;
System.out.println("Multiplication of two numbers =" + res);
}
}
public class division {
int res;
void div(int a, int b) {
res = a / b;
System.out.println("Division of two number =" + res);
}
}
public class TestCalculator {
public static void main(String args[]) {
calculator c = new calculator();
c.performAddition(1, 2);
c.performSubtraction(10,2);
c.performMultiplication(10,5);
c.performDivision(10,2);
}
}
7 a) code , execute and debug programs toper form string manipulation .
public class stringdemo {