1.
Write a program to print Hello World in Java
Program:-
public class main {
public static void main(String[] args) {
[Link](“Hello world”);
}
}
Output:-
Hello world
2. Experiment use of println() & print() functions by printing
few lines.
Program:-
public class Main {
public static void main(String[] args) {
[Link]("Hello");
[Link](" world");
[Link]("Hello");
[Link](" world");
Output:-
Hello
world
Hello world
3. Write a program to perform Arithmetic operations on 2
integer numbers. Accept numbers from user using Scanner
class.
Program:-
import [Link];
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter first integer number: ");
int num1 = [Link]();
[Link]("Enter second integer number: ");
int num2 = [Link]();
int sum = num1 + num2;
[Link](sum);
[Link]();
}
Output:-
Enter first integer number: 12
Enter second integer number: 23
35
4. Write same kind of program by accepting 2 ϐloat numbers
from user.
Program:-
import [Link];
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter first float number: ");
float num1 = [Link]();
[Link]("Enter second float number: ");
float num2 = [Link]();
float sum = num1 + num2;
[Link](sum);
[Link]();
Output:-
Enter first float number: 1.56
Enter second float number: 1.89
3.4499998
5. Input UserName & Address and print welcome message.
Program:-
import [Link];
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter your name: ");
String userName = [Link]();
[Link]("Enter your address: ");
String address = [Link]();
[Link]("\nWelcome, " + userName + "!");
[Link]("Your address is: " + address);
[Link]();
}
Output:-
Enter your name: taksh
Enter your address: harikrushna residency
Welcome, taksh!
Your address is: harikrushna residency