0% found this document useful (0 votes)
6 views4 pages

Java Programs Class 9

The document contains Java programs that demonstrate basic programming concepts such as checking if a number is odd or even, determining student grades, voting eligibility, finding the largest of three numbers, converting Celsius to Fahrenheit, calculating simple interest, checking divisibility, identifying leap years, and more. Each program uses the Scanner class for user input and includes conditional statements to produce outputs based on the input values. These examples serve as practical exercises for beginners to learn Java programming.

Uploaded by

bendaleyash2011
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)
6 views4 pages

Java Programs Class 9

The document contains Java programs that demonstrate basic programming concepts such as checking if a number is odd or even, determining student grades, voting eligibility, finding the largest of three numbers, converting Celsius to Fahrenheit, calculating simple interest, checking divisibility, identifying leap years, and more. Each program uses the Scanner class for user input and includes conditional statements to produce outputs based on the input values. These examples serve as practical exercises for beginners to learn Java programming.

Uploaded by

bendaleyash2011
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

Java Programs

1. Odd or Even
import [Link];
class OddEven {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
if (n % 2 == 0)
[Link]("Even");
else
[Link]("Odd");
}
}

2. Student Grade
import [Link];
class Grade {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int marks = [Link]();
if (marks >= 90)
[Link]("Grade A");
else if (marks >= 75)
[Link]("Grade B");
else if (marks >= 50)
[Link]("Grade C");
else
[Link]("Grade D");
}
}

3. Voting Eligibility
import [Link];
class Vote {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int age = [Link]();
if (age >= 18)
[Link]("Eligible to vote");
else
[Link]("Not eligible to vote");
}
}

4. Largest of Three Numbers


import [Link];
class Largest {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int a = [Link]();
int b = [Link]();
int c = [Link]();
if (a > b && a > c)
[Link]("Largest is " + a);
else if (b > c)
[Link]("Largest is " + b);
else
[Link]("Largest is " + c);
}
}

5. Celsius to Fahrenheit
import [Link];
class Temp {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
double c = [Link]();
double f = (c * 9 / 5) + 32;
[Link]("Fahrenheit = " + f);
if (c > 100)
[Link]("Warning: High Temperature");
}
}

6. Simple Interest
import [Link];
class SimpleInterest {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
double p = [Link]();
double r = [Link]();
double t = [Link]();
double si = (p * r * t) / 100;
[Link]("Simple Interest = " + si);
if (r > 10)
[Link]("High Interest Rate");
}
}

7. Divisible by 3 and 5
import [Link];
class Divisible {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
if (n % 3 == 0 && n % 5 == 0)
[Link]("Divisible by 3 and 5");
else
[Link]("Not divisible by 3 and 5");
}
}

8. Leap Year
import [Link];
class LeapYear {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int year = [Link]();
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
[Link]("Leap Year");
else
[Link]("Not a Leap Year");
}
}

9. Positive, Negative or Zero


import [Link];
class NumberCheck {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
if (n > 0)
[Link]("Positive");
else if (n < 0)
[Link]("Negative");
else
[Link]("Zero");
}
}
10. Volume of Cone
import [Link];
class Cone {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
double r = [Link]();
double h = [Link]();
double v = (1.0 / 3) * 3.14 * r * r * h;
[Link]("Volume = " + v);
}
}

11. Complementary Angles


import [Link];
class Angle {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int a = [Link]();
int b = [Link]();
if (a + b == 90)
[Link]("Complementary Angles");
else
[Link]("Not Complementary");
}
}

You might also like