[Go to site: main page, start]

0% found this document useful (0 votes)
2 views3 pages

Java Programs for Basic Algorithms

Uploaded by

roshneltilo13
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)
2 views3 pages

Java Programs for Basic Algorithms

Uploaded by

roshneltilo13
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

Example 1: Find the Smallest of Three

Numbers
Java Program
import [Link];

public class SmallestNumber {


public static void main(String[] args) {
Scanner input = new Scanner([Link]);
[Link]("Enter first number: ");
int a = [Link]();
[Link]("Enter second number: ");
int b = [Link]();
[Link]("Enter third number: ");
int c = [Link]();
if (a < b && a < c) {
[Link]("The smallest number is: " + a);
} else if (b < c) {
[Link]("The smallest number is: " + b);
} else {
[Link]("The smallest number is: " + c);
}
}
}

Example 1: Find the Smallest of Three


Numbers
Pseudocode
START
INPUT a, b, c
IF a < b AND a < c THEN
OUTPUT a is smallest
ELSE IF b < c THEN
OUTPUT b is smallest
ELSE
OUTPUT c is smallest
ENDIF
END
Instructions: Create the Pseudocode for the following java
programs
(see Example for reference)

Task 1: Determine if a Character is a Vowel or Consonant


import [Link];

public class LeapYearChecker {


public static void main(String[] args) {
Scanner input = new Scanner([Link]);

[Link]("Enter a year: ");


int year = [Link]();

if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {


[Link](year + " is a Leap Year.");
} else {
[Link](year + " is Not a Leap Year.");
}
}
}

Task 2: Grade Equivalent Checker

Java Program
import [Link];

public class GradeChecker {


public static void main(String[] args) {
Scanner input = new Scanner([Link]);

[Link]("Enter your grade (0–100): ");


int grade = [Link]();

if (grade >= 90) {


[Link]("Grade: A");
} else if (grade >= 80) {
[Link]("Grade: B");
} else if (grade >= 70) {
[Link]("Grade: C");
} else if (grade >= 60) {
[Link]("Grade: D");
} else {
[Link]("Grade: F");
}
}
}
Task 3: Determine Triangle Type

Java Program
import [Link];

public class TriangleType {


public static void main(String[] args) {
Scanner input = new Scanner([Link]);

[Link]("Enter side 1: ");


int side1 = [Link]();

[Link]("Enter side 2: ");


int side2 = [Link]();

[Link]("Enter side 3: ");


int side3 = [Link]();

if (side1 == side2 && side2 == side3) {


[Link]("The triangle is Equilateral.");
} else if (side1 == side2 || side2 == side3 || side1 == side3) {
[Link]("The triangle is Isosceles.");
} else {
[Link]("The triangle is Scalene.");
}
}
}

You might also like