0% found this document useful (0 votes)
2 views5 pages

Java Lab

The document contains multiple Java programs demonstrating basic programming concepts such as printing text, user input, arithmetic operations, and conditional statements. Each program showcases different functionalities, including printing user-entered numbers and names, calculating sums, checking even/odd status, and determining the largest number among three inputs. Overall, it serves as an introductory guide to Java programming for beginners.

Uploaded by

karthikpro56
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)
2 views5 pages

Java Lab

The document contains multiple Java programs demonstrating basic programming concepts such as printing text, user input, arithmetic operations, and conditional statements. Each program showcases different functionalities, including printing user-entered numbers and names, calculating sums, checking even/odd status, and determining the largest number among three inputs. Overall, it serves as an introductory guide to Java programming for beginners.

Uploaded by

karthikpro56
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

Program 1: Printing Text

public class AddingLines {


public static void main(String args[]){
[Link]("Welcome to the world of Java");
[Link]("Object Oriented Programming Concepts Lab");
[Link](“Object is the vital entity in OOPS”);
}
}

Program 2: Printing a user entered Number

import [Link];

public class HelloWorld {

public static void main (String[] args)

Scanner reader = new Scanner([Link]);

[Link]("Enter a number: ");

int number = [Link]();

[Link]("You entered: " + number);

Program 3: Printing a user entered Name

import [Link];

public class PrintName {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

[Link]("Enter your name: ");

String name = [Link]();

[Link]("Your name is: " + name);

}
Program 4: Sum of Two numbers

public class Sum {


public static void main(String args[]){
int num1, num2, result;
num1=10;
num2=15;
result=num1+num2;
[Link] ("The sum of two number is: " + result);
}
}

Program 5: Printing Sum of Two numbers using user input

import [Link];

public class SumTwoNumbers {

public static void main(String[] args) {

Scanner sc = new Scanner ([Link]);

[Link]("Enter first number: ");

int num1 = [Link]();

[Link]("Enter second number: ");

int num2 = [Link]();

int sum = num1 + num2;

[Link]("The sum is: " + sum);

Program 7: Input from user with different data types

import [Link];
public class UserInputDemo
{
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
[Link]("Enter an integer: ");
int intValue = [Link]();
[Link]("Enter a float: ");
float floatValue = [Link]();
[Link]("Enter a double: ");
double doubleValue = [Link]();
[Link]("Enter a character: ");
char charValue = [Link]().charAt(0);
[Link]("Enter a string: ");
String stringValue = [Link]();
[Link]("Enter a boolean (true/false): ");
boolean booleanValue = [Link]();
[Link]("\n You entered:");
[Link]("Integer: " + intValue);
[Link]("Float: " + floatValue);
[Link]("Double: " + doubleValue);
[Link]("Character: " + charValue);
[Link]("String: " + stringValue);
[Link]("Boolean: " + booleanValue);
}
}

Program 7: Check number odd or even

import [Link];

public class EvenOdd {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

[Link]("Enter a number: ");

int num = [Link]();

if(num % 2 == 0)

[Link]("The given number is an Even number");


else

[Link]("The given number is an Odd number");

Program 8: CHECK given number is positive/Negative/Zero

import [Link];

public class NumberCheck {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

[Link]("Enter a number: ");

int num = [Link]();

if(num > 0)

[Link]("The number is Positive.");

else if(num < 0)

[Link]("The number is Negative.");

else

[Link]("The number is Zero.");

Program 9: Biggest Number among three number

public class biggest {

public static void main(String[] args) {

int a = 25;

int b = 40;

int c = 18;

int largest;

if (a >= b && a >= c)

largest = a;
}

else if (b >= a && b >= c)

largest = b;

else

largest = c;

[Link]("The largest number is: " + largest);

You might also like