[go: up one dir, main page]

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

java ass 2

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)
31 views10 pages

java ass 2

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
You are on page 1/ 10

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;
System.out.println(sum);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/b);
System.out.println(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;
System.out.println(a+=50);
System.out.println(b-=32);
System.out.println(a*=26);
System.out.println(a/=20);
System.out.println(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;
System.out.println(x<y);
System.out.println(x<=500);
System.out.println("===========");
System.out.println(y>100);
System.out.println(y>=200);
System.out.println("===========");
System.out.println(x==y);
System.out.println(x!=y);
System.out.println(x==150);
System.out.println(x==1000);
System.out.println(x!=190);
System.out.println(y!=999);
System.out.println("===========");
}
}

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

System.out.println(nameTom + " " + ageTom + " " + heightTom + " " + genderTom + " |
"
+ nameJerry + " " + ageJerry + " " + heightJerry + " " + genderJerry);

}
}

O/P:
ASSIGNMENT -2
12/03/25
1.Get 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)
{
System.out.println("Pass");
}
else
{
System.out.println("Fail");
}

2.Get input for Variable Income. If Income is greater than 7000 scholarship is available Else
not eligible for scholarship.

Int income = 7500;

if (income > 7000)


{
System.out.println(“Scholarship is available”);
}
else
{
System.out.println(“Not eligible for scholarship”);
}

3.Get 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)
{
System.out.println("The number is divisible by 3 and 5");
}
else
{
System.out.println("The number is not divisible by 3 and 5");
}

4.WJP to find the number is even or odd

int n = 8;

if (n % 2 == 0)
System.out.println("Even number");

else

System.out.println("Odd number");

5.What 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)

{
System.out.println("You need to improve.");
}
else if (score <= 70)
{
System.out.println("Good job!");
}
else
{
System.out.println("Excellent Performance!");
}

6.What 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 (color.equalsIgnoreCase("red")) System.out.println("Stop.");
else if (color.equalsIgnoreCase("yellow")) System.out.println("Get Ready.");

else if (color.equalsIgnoreCase("green")) System.out.println("Go.");

else System.out.println("Invalid input.");

7.WJP to check the number is >=

10.(Simple if)?

int numCheck = 12;

if (numCheck >= 10)


{
System.out.println("The number is greater than or equal to 10.");
}

8.WJP to check person is Male or Not.(Simple if)


char gender = 'M';

if (gender == 'M')
{
System.out.println("Male");
}

9.WJP to check number is >= 10 or not (if-else)


int checkNum = 7;

if (checkNum >= 10)


{
System.out.println("Number is greater than or equal to 10.");
}
else
{
System.out.println("Number is less than 10.");
}

10.WJP to check Person is Eligible for vote or not?(if-else)


int age = 20;

if (age >= 18)


{
System.out.println("Eligible to vote.");
}
else
{
System.out.println("Not eligible to vote.");
}

11.WJP to compare 2 numbers (if-else-if)

int num1 = 25, num2 = 30;

if (num1 > num2) System.out.println(num1 + " is greater than " + num2);


else if (num1 < num2) System.out.println(num2 + " is greater than " + num1);
else System.out.println("Both numbers are equal.");

12.WJP to Check the person gender (if-else-if)


char g = 'F';

if (g == 'M') System.out.println("Male");
else if (g == 'F') System.out.println("Female");

else System.out.println("Other");

13.WJP to check the no is '+'ve or '-'ve.

int numSign = -5;


if (numSign > 0) System.out.println("Positive number.");
else if (numSign < 0) System.out.println("Negative number.");

else System.out.println("Zero.");

14.WJP to find largest among three numbers(Else-if ladder)


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

if (a > b && a > c) System.out.println(a + " is the largest.");

else if (b > c) System.out.println(b + " is the largest.");

else System.out.println(c + " is the largest.");

15.WJP 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) System.out.println("Passed with Distinction");

else if (marks >= 60) System.out.println("First Class");

else if (marks >= 35) System.out.println("Pass");

else if (marks >= 0) System.out.println("Fail");


else System.out.println("Not valid");

16.WJP to Compare two numbers(Nested-if)


int x = 40, y = 35;

if (x != y) {
if (x > y) System.out.println(x + " is greater.");

else System.out.println(y + " is greater.");

} else System.out.println("Both numbers are equal.");

17.WJP to largest of three numbers(Nested-if)//Placement Question

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

if (p > q) {
if (p > r) System.out.println(p + " is the largest.");

else System.out.println(r + " is the largest.");

} else {
if (q > r) System.out.println(q + " is the largest.");

else System.out.println(r + " is the largest.");

}
18.WJP for Gmail Login (Nested-if)
String username = "user", password = "pass123";

if (username.equals("user")) {

if (password.equals("pass123")) System.out.println("Login successful.");

else System.out.println("Invalid password.");

} else System.out.println("Invalid username.");

19.WJP to signup in Matrimonial Variable->age, gender (Nested-if)


int userAge = 22;

char userGender = 'F';

if (userAge >= 18) {

if (userGender == 'M') System.out.println("Male user can sign up.");


else if (userGender == 'F') System.out.println("Female user can sign up.");

else System.out.println("Invalid gender.");

} else System.out.println("User is underage.");


}
}

O/P:-

You might also like