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

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...
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.
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.
In java. Prefer Bluej Create a program in java that calculates area and perimeter of a...
In java. Prefer Bluej Create a program in java that calculates area and perimeter of a square - use a class and test program to calculate the area and perimeter; assume length of square is 7 ft.
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...
Create a java random program from example (1,2,3,4,5,6,7,8,9,10) But do exception for number 7 when you...
Create a java random program from example (1,2,3,4,5,6,7,8,9,10) But do exception for number 7 when you run the program first time for example it will print 3 then when you run the program for the second time it will give a random number for example 9 but number 7 will not be printed because we need you to do exception for it.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT