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

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...
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
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
1.Write a Java program that inputs a binary number and displays the same number in decimal....
1.Write a Java program that inputs a binary number and displays the same number in decimal. 2.Write Java program that inputs a decimal number and displays the same number in binary.
CREATE A NEW Java PROGRAM that demonstrates : 1.1 numeric and 1 string exception 2. Create...
CREATE A NEW Java PROGRAM that demonstrates : 1.1 numeric and 1 string exception 2. Create your own user defined exception, COMMENT it well, and add code so that it is thrown.
JAVA JAVA JAVA JAVA, How to determine if there is more than one number that appeared...
JAVA JAVA JAVA JAVA, How to determine if there is more than one number that appeared the X amount of times. (For example there are 3 numbers which occured 50 times so I want the output to show which 3 numbers occured 50 times) This is the code import java.util.Random; public class MostLeastOccurring { public static void main(String[] args) { Random random = new Random(); int x = 1000; int[] array = new int[x]; for (int i = 0; i...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT