0% found this document useful (0 votes)
4 views7 pages

Program

The document contains several Java programs demonstrating basic functionalities such as printing 'Hello World', using println() and print() functions, performing arithmetic operations on integers and floats, and accepting user input for name and address. Each program includes the code and the expected output. The examples illustrate fundamental programming concepts in Java using the Scanner class for user input.

Uploaded by

regil69631
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

Program

The document contains several Java programs demonstrating basic functionalities such as printing 'Hello World', using println() and print() functions, performing arithmetic operations on integers and floats, and accepting user input for name and address. Each program includes the code and the expected output. The examples illustrate fundamental programming concepts in Java using the Scanner class for user input.

Uploaded by

regil69631
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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

You might also like