0% found this document useful (0 votes)
188 views10 pages

Java Operators and Conditional Programs

The document contains Java programming assignments that cover various operators and control structures. It includes examples of arithmetic, assignment, relational operators, and conditional statements such as if-else and nested if. Each section provides code snippets along with expected outputs for tasks like checking eligibility, comparing numbers, and determining traffic light actions.

Uploaded by

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

Java Operators and Conditional Programs

The document contains Java programming assignments that cover various operators and control structures. It includes examples of arithmetic, assignment, relational operators, and conditional statements such as if-else and nested if. Each section provides code snippets along with expected outputs for tasks like checking eligibility, comparing numbers, and determining traffic light actions.

Uploaded by

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

ASSIGNMENT -1

10/03/25

1 . Write a java program for Arithmetic operator ?

class Arthematicoperator {
public static void main(String[] args) {
int a = 999;
int b = 888;
int sum = a+b;
[Link](sum);
[Link](a-b);
[Link](a*b);
[Link](a/b);
[Link](a%b);
}
}

O/P:

2 . Write a java program for Assignment operator?

class Assignmentoperator {
public static void main(String[] args) {
int a = 80;
int b = 90;
[Link](a+=50);
[Link](b-=32);
[Link](a*=26);
[Link](a/=20);
[Link](a%=92);
}
}
O/P:

3 . write a java program for Relational operator ?

class Relationaloperator {
public static void main(String[] args) {
int x = 1000;
int y = 999;
[Link](x<y);
[Link](x<=500);
[Link]("===========");
[Link](y>100);
[Link](y>=200);
[Link]("===========");
[Link](x==y);
[Link](x!=y);
[Link](x==150);
[Link](x==1000);
[Link](x!=190);
[Link](y!=999);
[Link]("===========");
}
}

O/P:
4 . Write a java program print name, age, height, gender of Tom and Jerry?

class Tom {
public static void main(String[] args) {

String nameTom = "Tom";


int ageTom = 5;
double heightTom = 1.2;
String genderTom = "Male";

String nameJerry = "Jerry";


int ageJerry = 3;
double heightJerry = 0.3;
String genderJerry = "Male";

[Link](nameTom + " " + ageTom + " " + heightTom + " " + genderTom + " |
"
+ nameJerry + " " + ageJerry + " " + heightJerry + " " + genderJerry);

}
}

O/P:
ASSIGNMENT -2
12/03/25
[Link] input for Variable Mark. If mark > 35 print pass. Else Print fail.

public class Assignment02 {


public static void main(String[] args) {
int mark = 40;
if (mark > 35)
{
[Link]("Pass");
}
else
{
[Link]("Fail");
}

[Link] input for Variable Income. If Income is greater than 7000 scholarship is available Else
not eligible for scholarship.

Int income = 7500;

if (income > 7000)


{
[Link](“Scholarship is available”);
}
else
{
[Link](“Not eligible for scholarship”);
}

[Link] input for a number and check whether it is divisible by both 3 and 5 or not. If yes then
print, the number is divisible by 3 and 5 print the number is not divisible by 3 and 5 How to
find the number is divisible by 3 or Not?

int num = 15;


if (num % 3 == 0 && num % 5 == 0)
{
[Link]("The number is divisible by 3 and 5");
}
else
{
[Link]("The number is not divisible by 3 and 5");
}

[Link] to find the number is even or odd

int n = 8;

if (n % 2 == 0)
[Link]("Even number");

else

[Link]("Odd number");

[Link] is the score of the game? -if the score is less than 50,print "You need to improve." -if
the score is between 50 and 70 (inclusive), print "Good job!" -if the score is greater than
70,print "Excellent Performance!".

int score = 65;

if (score < 50)

{
[Link]("You need to improve.");
}
else if (score <= 70)
{
[Link]("Good job!");
}
else
{
[Link]("Excellent Performance!");
}

[Link] is the color of the traffic Light? -If the answer is "red," print "Stop." -If the answer is
"yellow" print "Get Ready". -If the answer is "green," print "Go."

String color = "red";


if ([Link]("red")) [Link]("Stop.");
else if ([Link]("yellow")) [Link]("Get Ready.");

else if ([Link]("green")) [Link]("Go.");

else [Link]("Invalid input.");

[Link] to check the number is >=

10.(Simple if)?

int numCheck = 12;

if (numCheck >= 10)


{
[Link]("The number is greater than or equal to 10.");
}

[Link] to check person is Male or Not.(Simple if)


char gender = 'M';

if (gender == 'M')
{
[Link]("Male");
}

[Link] to check number is >= 10 or not (if-else)


int checkNum = 7;

if (checkNum >= 10)


{
[Link]("Number is greater than or equal to 10.");
}
else
{
[Link]("Number is less than 10.");
}

[Link] to check Person is Eligible for vote or not?(if-else)


int age = 20;

if (age >= 18)


{
[Link]("Eligible to vote.");
}
else
{
[Link]("Not eligible to vote.");
}

[Link] to compare 2 numbers (if-else-if)

int num1 = 25, num2 = 30;

if (num1 > num2) [Link](num1 + " is greater than " + num2);


else if (num1 < num2) [Link](num2 + " is greater than " + num1);
else [Link]("Both numbers are equal.");

[Link] to Check the person gender (if-else-if)


char g = 'F';

if (g == 'M') [Link]("Male");
else if (g == 'F') [Link]("Female");

else [Link]("Other");

[Link] to check the no is '+'ve or '-'ve.

int numSign = -5;


if (numSign > 0) [Link]("Positive number.");
else if (numSign < 0) [Link]("Negative number.");

else [Link]("Zero.");

[Link] to find largest among three numbers(Else-if ladder)


int a = 10, b = 15, c = 5;

if (a > b && a > c) [Link](a + " is the largest.");

else if (b > c) [Link](b + " is the largest.");

else [Link](c + " is the largest.");

[Link] to display Student Result Note:- 80-100 -> Passed with Distinction 60-79 -> First Class
35-59 -> Pass 0-34 -> Fail others -> not valid

int marks = 85;

if (marks >= 80 && marks <= 100) [Link]("Passed with Distinction");

else if (marks >= 60) [Link]("First Class");

else if (marks >= 35) [Link]("Pass");

else if (marks >= 0) [Link]("Fail");


else [Link]("Not valid");

[Link] to Compare two numbers(Nested-if)


int x = 40, y = 35;

if (x != y) {
if (x > y) [Link](x + " is greater.");

else [Link](y + " is greater.");

} else [Link]("Both numbers are equal.");

[Link] to largest of three numbers(Nested-if)//Placement Question

int p = 18, q = 25, r = 10;

if (p > q) {
if (p > r) [Link](p + " is the largest.");

else [Link](r + " is the largest.");

} else {
if (q > r) [Link](q + " is the largest.");

else [Link](r + " is the largest.");

}
[Link] for Gmail Login (Nested-if)
String username = "user", password = "pass123";

if ([Link]("user")) {

if ([Link]("pass123")) [Link]("Login successful.");

else [Link]("Invalid password.");

} else [Link]("Invalid username.");

[Link] to signup in Matrimonial Variable->age, gender (Nested-if)


int userAge = 22;

char userGender = 'F';

if (userAge >= 18) {

if (userGender == 'M') [Link]("Male user can sign up.");


else if (userGender == 'F') [Link]("Female user can sign up.");

else [Link]("Invalid gender.");

} else [Link]("User is underage.");


}
}

O/P:-

You might also like