0% found this document useful (0 votes)
2 views

import java

The document contains three Java programs: one for converting numerical grades to letter grades, another for identifying colors based on input codes, and a third for performing basic arithmetic operations based on user selection. Each program uses a Scanner to read user input and provides output based on conditional statements. There are some minor issues in the code, such as incorrect letter grade assignment and unnecessary semicolons in the color program.

Uploaded by

ALDRIN LLAGAS
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

import java

The document contains three Java programs: one for converting numerical grades to letter grades, another for identifying colors based on input codes, and a third for performing basic arithmetic operations based on user selection. Each program uses a Scanner to read user input and provides output based on conditional statements. There are some minor issues in the code, such as incorrect letter grade assignment and unnecessary semicolons in the color program.

Uploaded by

ALDRIN LLAGAS
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.util.

Scanner;
public class Grade {
public static void main(String[] args) {
double grade;
Scanner read = new Scanner(System.in);
System.out.print("Enter Grade ");
grade = read.nextDouble();

if(grade>=90 && grade <=100)


{
System.out.print(grade+" is equivalent to LETTER GRADE A");
}
if(grade>=80 && grade <=89)
{
System.out.print(grade+" is equivalent to LETTER GRADE B");
}
if(grade>=70 && grade <=79)
{
System.out.print(grade+" is equivalent to LETTER GRADE C");
}
if(grade>=60 && grade <=69)
{
System.out.print(grade+" is equivalent to LETTER GRADE D");
}
if(grade<60)
{
System.out.print(grade+"is equivalent to LETTER GRADE A");
}

}
}

import java.util.Scanner;
public class Color {
public static void main(String[] args) {
char code;
Scanner read = new Scanner(System.in);
System.out.print("Enter Code ");
code = read.next().toLowerCase().charAt(0);

if(code=='R' || code=='r');
{
System.out.print("\nColor code" + code + "is equivalent to RED");
}
if(code=='G' || code=='g');
{
System.out.print("\nColor code" + code + "is equivalent to
GREEN");
}
if(code=='B' || code=='b');
{
System.out.print("\nColor code" + code + "is equivalent to BLUE");
}
if(code=='Y' || code=='y');
{
System.out.print("\nColor code" + code + "is equivalent to
YELLOW");
}
if(code!='R'&& code!='r'&&
code!='G'&& code!='g'&&
code!='B'&& code!='b'&&
code!='Y'&& code!='y')
{
System.out.println("\nColor Code"+code+" is invalid code");
}

}
}
import java.util.Scanner;
public class Operator {
public static void main(String[] args) {
char option;
double number1, number2, answer;

Scanner read = new Scanner(System.in);


System.out.println("\n\t\t\t\t M E N U");
System.out.println("\t\t\t---------------------------------");
System.out.println("\t\t\t\t[A] Addition");
System.out.println("\t\t\t\t[B] Subtraction");
System.out.println("\t\t\t\t[C] Multiplication");
System.out.println("\t\t\t\t[D] Division");

System.out.print("\n\t\t\tSelect an option [A,B,C or D]:");


option = read.next().charAt(0);
if (option == 'A' || option == 'a') {
System.out.print("\n\t\t\tEnter first number: ");
number1 = read.nextDouble();
System.out.print("\n\t\t\tEnter second number: ");
number2 = read.nextDouble();
answer = number1 + number2;
System.out.print("\n\t\t\tSum: " + answer);
}
if (option == 'B' || option == 'b') {
System.out.print("\n\t\t\tEnter first number: ");
number1 = read.nextDouble();
System.out.print("\n\t\t\tEnter second number: ");
number2 = read.nextDouble();
answer = number1 - number2;
System.out.print("\n\t\t\tDifference: " + answer);
}
if (option == 'C' || option == 'c') {
System.out.print("\n\t\t\tEnter first number: ");
number1 = read.nextDouble();
System.out.print("\n\t\t\tEnter second number: ");
number2 = read.nextDouble();
answer = number1 * number2;
System.out.print("\n\t\t\tProduct: " + answer);
}
if (option == 'D' || option == 'd') {
System.out.print("\n\t\t\tEnter first number: ");
number1 = read.nextDouble();
System.out.print("\n\t\t\tEnter second number: ");
number2 = read.nextDouble();
answer = number1 / number2;
System.out.print("\n\t\t\tQuotient: " + answer);
}
if (option != 'A' && option != 'a' &&
option != 'B' && option != 'b' &&
option != 'C' && option != 'c' &&
option != 'D' && option != 'd') {
System.out.println("\n\t\t\tinvalid option");
System.out.println("\n\t\t\tValid choices are A,B,c or D only");

}
}
}

You might also like