0% found this document useful (0 votes)
5 views6 pages

Java Week0

The document contains a series of Java programming exercises for an Object Oriented Programming lab. It includes five problems, each with a corresponding Java program that demonstrates basic programming concepts such as printing messages, reading input, performing arithmetic operations, and checking number properties. Each problem is followed by the Java code and expected output.
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)
5 views6 pages

Java Week0

The document contains a series of Java programming exercises for an Object Oriented Programming lab. It includes five problems, each with a corresponding Java program that demonstrates basic programming concepts such as printing messages, reading input, performing arithmetic operations, and checking number properties. Each problem is followed by the Java code and expected output.
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

____________________________________________________________________________

Object Oriented Programing Lab


WEEK-1
NAME : [Link] DATE :23-10-2022

HTNO : 22R25A6609

BRANCH : CSM

SECTION : B

PROBLEM STATEMENT:
1. Write a java program to print a message.
Java Program:
import [Link].*;

class Hello

public static void main(String[] args)

[Link]("Hello World");

OUTPUT:
PROBLEM STATEMENT:
2. Write a java program to read data through console.

Java Program:
import [Link].*;

import [Link];

class Print

public static void main(String args[])

Scanner in = new Scanner([Link]);

[Link]("Enter the values of a and b");

int a = [Link]();

int b = [Link]();

[Link]("Hello World! "+(a+b));

OUTPUT:
PROBLEM STATEMENT:
3. Write a java program to perform arithmetic operations.

Java Program:
import [Link].*;
import [Link];
class ArithmeticOperators
{
public static void main(String[] args)
{
Scanner in = new Scanner([Link]);
[Link]("Enter the values of a and b");
int a = [Link]();
int b = [Link]();
[Link]("a+b "+(a+b));
[Link]("a-b "+(a-b));
[Link]("a*b "+(a*b));
[Link]("a/b "+(a/b));
[Link]("a%b "+(a%b));
}
}

OUTPUT:
PROBLEM STATEMENT:
4. Write a java program to check whether given number is even
or odd.

Java Program:
import [Link].*;
import [Link];
class EvenOdd
{
public static void main(String[] agrs)
{
Scanner in = new Scanner([Link]);
int n = [Link]();
if(n%2 == 0)
{
[Link](n+" is Even");
}
else
{
[Link](n+" is Odd");
}
}
}

OUTPUT:
PROBLEM STATEMENT:
5. Write a java program to check whether given number is
positive or negative.
Java Program:
import [Link].*;
import [Link];
class PositiveNegative
{
public static void main(String[] args)
{
Scanner in = new Scanner([Link]);
[Link]("Enter the number ");
int n = [Link]();
if(n > 0)
{
[Link](n+" is positive");
}
else
{
[Link](n+" is negative");
}
}
}

OUTPUT:

You might also like