Question

In: Computer Science

1- Create a Java program to determine a certain number whether that number is odd or...

1- Create a Java program to determine a certain number whether that number is odd or even.
Hint : use arithmetic operators and expressions to find the odd or even numbers.

2- Create a Java program to ask a user to enter a name and password as shown below:
name is “Ahmed” and his password is 2321 or name is “Ali” and his password is 6776 . The program shows a greeting “Hi ..Welcome to my program” if the user is “Ahmed” Or “Ali” otherwise it will shows a message “Sorry!! I don’t recognize you”.
Hint : use conditional and Boolean Operators.

3- Create a Java problem to ask a user to enter a GPA grade and based on that grade it will determine if the user is one of the Honor list or not.
Hint :   
- GPA is more than or equal 3.90 shows message “Excellent .. you are at First honor”
- GPA is more than or equal 3.70 shows message “Excellent .. you are at Second honor ”
- GPA is More than or equal 3.50 shows message “Excellent .. you are at Third honor” GPA is less than 3.50 and more than or equal 2.00 shows message “Good .. Work hard to raise your GPA”
- Otherwise shows message “WORK HARD … You are in trouble”

Solutions

Expert Solution

  • 1).
  • Code:-

import java.util.Scanner;
class Even_Odd{
public static void main(String[] args){
int num;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number to check: ");
num = in.nextInt();
if(num % 2 == 0){
System.out.println("Even");
} else {
System.out.println("Odd");
}
}
}

  • Output:-

  • 2).
  • Code:-

import java.util.Scanner;
class User{
public static void main(String[] args){
int password;
String username;

Scanner in = new Scanner(System.in);
//get username from user
System.out.print("Enter your username: ");
username = in.next();
//get password from user
System.out.print("Enter your password: ");
password = in.nextInt();
//if username is Ahmed and password is 2321
if(username.equals("Ahmed") && password==2321){
System.out.println("Hi ..Welcome to my program");
}
//if username is Ali and password is 6776
else if(username.equals("Ali") && password==6776){
System.out.println("Hi ..Welcome to my program");
} //if username and password are not recognized
else {
System.out.println("Sorry!! I don’t recognize you");
}
in.close();
}
}

  • Output:-

  • 3).
  • Code:-

import java.util.Scanner;
class Gpa {
public static void main(String[] args){
float gpa;
Scanner in = new Scanner(System.in);

System.out.print("Enter gpa: ");
gpa = in.nextFloat();
// Gpa > 3.90
if(gpa >= 3.90){
System.out.println("Excellent .. you are at First honor");
} // Gpa > 3.70
else if(gpa >= 3.70){
System.out.println("Excellent .. you are at Second honor");
} // Gpa > 3.5
else if(gpa >= 3.50){
System.out.println("Excellent .. you are at Third honor");
} //Gpa < 3.50 and > 2.00
else if(gpa < 3.50 && gpa >= 2.00){
System.out.println("Good .. Work hard to raise your GPA");
} // Otherwise
else {
System.out.println("WORK HARD … You are in trouble");
}
in.close();
}
}

  • Output:-

Thank You...!


Related Solutions

Create an application that checks whether an integer is an odd or even number. Welcome to...
Create an application that checks whether an integer is an odd or even number. Welcome to the Odd/Even Checker! Enter an integer: ten Error! Invalid integer. Try again. Enter an integer: 10.3 Error! Invalid integer. Try again. Enter an integer: 10 The number 10 is even. Continue? (y/n): Error! This entry is required. Try again. Continue? (y/n): y Enter an integer: 9 The number 9 is odd. Continue? (y/n): n Specifications: Create a version of the Console class presented in...
Write a program to test whether a number provided from key board input is either odd...
Write a program to test whether a number provided from key board input is either odd or even. Don't forget the case that 0 is an even number. for C++ please
java program Create a program that creates and prints a random phone number using the following...
java program Create a program that creates and prints a random phone number using the following format: XXX-XXX-XXXX. Make sure your output include the dashes.  Do not let the first three digits contain an 8 or 9 (HINT: do not be more restrictive than that) and make sure that the second set of three digits is not greater than 773. Helpful Hint:   Think though the easiest way to construct the phone number. Each digit does do not have to be determined...
C++ Create a program that checks whether a number is a prime number and displays its...
C++ Create a program that checks whether a number is a prime number and displays its factors if it is not a prime number. Console Prime Number Checker Please enter an integer between 1 and 5000: 5 5 is a prime number. Try again? (y/n): y Please enter an integer between 1 and 5000: 6 6 is NOT a prime number. It has 4 factors: 1 2 3 6 Try again? (y/n): y Please enter an integer between 1 and...
Java Programming Create a program that prompts the user for an integer number and searches for...
Java Programming Create a program that prompts the user for an integer number and searches for it within an array of 10 elements. What is the average number of comparisons required to find an element in the array? Your program should print the number of comparisons required to find the number or determine that the number does not exist. Try finding the first and last numbers stored in the array. Run your program several times before computing the average.
Write c code to determine if a binary number is even or odd. If it is...
Write c code to determine if a binary number is even or odd. If it is odd, it outputs 1, and if it is even, it outputs 0. It has to be less than 12 operations. The operations have to be logical, bitwise, and arithmetic.
Java program to print all the powers of 2 below a certain number. Calculate sum, accept...
Java program to print all the powers of 2 below a certain number. Calculate sum, accept upper limit and make sure sum variable is long type.   Run- Enter the upper limit: 100 5 + 8 + 9 + 11 + 20 + 32 + 30 = 115
Write a program in java to determine whether a given function F from the set {0,1,2,3,...,m}...
Write a program in java to determine whether a given function F from the set {0,1,2,3,...,m} to (0,1,2,3,...,n} is one-to-one and/or onto. The inputs to your program will be: - an integer m - an integer n, and - a two dimensional boolean array F of size (m+1) x (n+1), where F[ i , j ] = 1 if F(i) = j.
Java Program 1. Write a program that asks the user: “Please enter a number (0 to...
Java Program 1. Write a program that asks the user: “Please enter a number (0 to exit)”. Your program shall accept integers from the user (positive or negative), however, if the user enters 0 then your program shall terminate immediately. After the loop is terminated, return the total sum of all the previous numbers the user entered. a. What is considered to be the body of the loop? b. What is considered the control variable? c. What is considered to...
Write a Java program that calculates a random number 1 through 100. The program then asks...
Write a Java program that calculates a random number 1 through 100. The program then asks the user to guess the number.If the user guesses too high or too low then the program should output "too high" or "too low" accordingly.The program must let the user continue to guess until the user correctly guesses the number. ★Modify the program to output how many guesses it took the user to correctly guess the right number
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT