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);