1. Let the user enter a score (0-100), determine which range the score belongs to and output the results (first draw a flowchart in Word)
(90-100->a 70-90->b 60-70->c <60--d)
Import Java.util.Scanner;
public class Problem1 {
public static void Main (string[] args) {
Scanner scan=new Scanner (system.in);
SYSTEM.OUT.PRINTLN ("Please output a score (0-100):");
int Score=scan.nextint ();
if (score<=100&&score>=90) {
System.out.println ("A");
}else if (score<90&&score>=70) {
System.out.println ("B");
}else if (score<70&&score>=60) {
System.out.println ("C");
}else if (score<60&&score>=0) {
System.out.println ("D");
}else{
SYSTEM.OUT.PRINTLN ("You have entered the wrong score.) ");
}
}
}
2. Let the user enter a positive integer
1) Determine whether the number is odd or even, and output the judging result
2) Determine if the number is a narcissus number and output the result (only 3 digits to consider)
Import Java.util.Scanner;
public class Problem2 {
public static void Main (string[] args) {
Scanner scan=new Scanner (system.in);
System.out.print ("Please enter a positive integer:");
int Num=scan.nextint ();
if (num<=0) {
System.out.println ("The number you entered is incorrect");
}else if (num%2==0) {
System.out.println ("The number is even");
}else{
System.out.println ("The number is odd");
}
int ge=num;
int SHI=NUM/10;
int bai=num/100;
if (num>=100&&num<1000&&ge*ge*ge+shi*shi*shi+bai*bai*bai==num) {
System.out.println ("The number is the number of daffodils");
}else if (num>=100&&num<1000&&ge*ge*ge+shi*shi*shi+bai*bai*bai!=num) {
System.out.println ("The number is not the number of daffodils");
}
//
for (int x=100;x<1000;x++) {
int ge=x;
int SHI=X/10;
int bai=x/100;
if (ge*ge*ge+shi*shi*shi+bai*bai*bai==x) {
SYSTEM.OUT.PRINTLN (x);
SYSTEM.OUT.PRINTLN (GE);
System.out.println (shi);
System.out.println (BAI);
// }
// }
}
}
3. Let the user enter a number, must be 1 to 7 (if the input is wrong, then the error), and then according to the number of user input to determine the day of the week (1: Monday, 2: Tuesday, ....., 7: Sunday. Requires judgment week using switch structure to complete)
Import Java.util.Scanner;
public class Problem3 {
public static void Main (string[] args) {
Scanner scan=new Scanner (system.in);
System.out.println ("Please enter Number (1-7)");
int Number=scan.nextint ();
Switch (number) {
Case 1:
System.out.println ("Monday");
Break
Case 2:
System.out.println ("Tuesday");
Break
Case 3:
System.out.println ("Wednesday");
Break
Case 4:
System.out.println ("Thursday");
Break
Case 5:
System.out.println ("Friday");
Break
Case 6:
System.out.println ("Saturday");
Break
Case 7:
System.out.println ("Sunday");
Break
Default:
System.out.println ("The number you entered is incorrect");
Break
}
}
5. Let the user enter a year (1900-2100, if not in this range, then prompt error), determine whether the year is a leap or common year.
Leap year rules: 4 Years A leap, a century does not leap; 400 years a leap.
Import Java.util.Scanner;
public class Problem5 {
public static void Main (string[] args) {
Scanner scan=new Scanner (system.in);
System.out.print ("Please enter a year (1900-2100):");
int Year=scan.nextint ();
if (year<1900| | YEAR>2100) {
SYSTEM.OUT.PRINTLN ("You entered the wrong year");
}else if (year>=1900&&year<=2100) {
if (year%4==0| | year0!=0) &&[email protected]==0) {
System.out.println (year+ "Years is a leap year");
}else{
SYSTEM.OUT.PRINTLN (year+ "Year is common year");
}
}
}
}
6. Let the user enter 3 numbers and then output in order from small to large.
Import Java.util.Scanner;
public class Problem6 {
public static void Main (string[] args) {
Scanner scan=new Scanner (system.in);
System.out.print ("Please enter three different numbers, \ n The first number:");
int Num1=scan.nextint ();
System.out.print ("second number:");
int Num2=scan.nextint ();
System.out.print ("Third number:");
int Num3=scan.nextint ();
int max=num1;
if (max>num2) {
if (max>num3) {
if (num2>num3) {
System.out.println (num3+ "," +num2+ "," +num1 ");
}else{
System.out.println (num2+ "," +num3+ "," +num1 ");
// }
}else{
System.out.println (num2+ "," +num1+ "," +num3 ");
// }
}else if (max
max=num2;
if (max>num3) {
if (num1>num3) {
System.out.println (num3+ "," +num1+ "," +num2 ");
}else{
System.out.println (num1+ "," +num3+ "," +num2 ");
// }
}else{
System.out.println (num1+ "," +num2+ "," +num3 ");
// }
// }
int temp;
if (num1>num2) {
temp=num2;
NUM2=NUM1;
Num1=temp;
}
if (num1>num3) {
TEMP=NUM3;
NUM3=NUM1;
Num1=temp;
}
if (num2>num3) {
TEMP=NUM3;
num3=num2;
Num2=temp;
}
System.out.println (num1+ "," +num2+ "," +num3 ");
}
}
7. Let the user enter a number between 1-9999 (if the input error, prompt error), reverse output the user input number.
Import Java.util.Scanner;
public class Problem7 {
public static void Main (string[] args) {
Scanner scan = new Scanner (system.in);
System.out.println ("Please enter a number of 1-9999");
int number = Scan.nextint ();
int GE = number% 10;
int shi = number/10% 10;
int bai = number/100% 10;
int qian = number/1000% 10;
if (number <= 0) {
SYSTEM.OUT.PRINTLN ("You entered the error");
} else if (number < 10) {
SYSTEM.OUT.PRINTLN ("Reverse output Result:" + ge);
} else if (number < 100) {
if (ge = = 0) {
SYSTEM.OUT.PRINTLN ("Reverse output Result:" + shi);
} else {
SYSTEM.OUT.PRINTLN ("Reverse output Result:" + ge + shi);
}
} else if (number < 1000) {
if (ge = = 0&&shi==0) {
SYSTEM.OUT.PRINTLN ("Reverse output Result:" +bai);
} else if (ge==0) {
SYSTEM.OUT.PRINTLN ("Reverse output Result:" + Shi + bai);
}else{
SYSTEM.OUT.PRINTLN ("Reverse output Result:" + ge + shi + bai);
}
} else if (number < 10000) {
if (ge = = 0&&shi==0&&bai==0) {
SYSTEM.OUT.PRINTLN ("Reverse output Result:" + qian);
} else if (ge==0&&shi==0) {
SYSTEM.OUT.PRINTLN ("Reverse output Result:" + Bai + Qian);
}else if (ge==0) {
SYSTEM.OUT.PRINTLN ("Reverse output Result:" + Shi+bai + qian);
}else{
SYSTEM.OUT.PRINTLN ("Reverse output Result:" + Ge+shi+bai + qian);
}
} else {
SYSTEM.OUT.PRINTLN ("You entered the error");
}
}
}
8. Let the user enter a 5-digit number, determine whether it is a palindrome number, output judgment results.
Palindrome Number: If 12321 is a palindrome number, million is the same as the digit, 10 bits and thousands of the same.
Import Java.util.Scanner;
public class Problem8 {
public static void Main (string[] args) {
Scanner scan=new Scanner (system.in);
System.out.println ("Please enter a five-digit number");
int Num=scan.nextint ();
int ge=num;
int SHI=NUM/10;
int bai=num/100;
int qian=num/1000;
int wan=num/10000;
if (num<10000| | num>=100000) {
System.out.println ("The number you entered is incorrect");
}else{
if (Ge==wan&&shi==qian) {
System.out.println ("The number is a palindrome number");
}else{
System.out.println ("The number is not a palindrome number");
}
}
}
}
10. The bonus awarded by the Enterprise is based on the profit percentage. Profit (I) less than or equal to $100,000, the bonus can be raised by 10%, the profit is higher than $100,000, less than $200,000, less than 100,000 of the portion of the 10% commission, higher than the portion of 100,000 yuan, Cocoa Commission 7.5%, 200,000 to 400,000, higher than 200,000 yuan of the portion, can commission 5% ; Between 400,000 and 600,000 is higher than the portion of 400,000 yuan, can commission 3%, 600,000 to 1 million, higher than 600,000 yuan portion, can commission 1.5%, higher than 1 million yuan, the portion of more than 1 million yuan by 1% Commission, from the keyboard input month profit I, the total bonus should be issued?
Import Java.util.Scanner;
public class PROBLEM10 {
public static void Main (string[] args) {
Scanner scan=new Scanner (system.in);
System.out.println ("Please enter profit I (unit: million)");
int I=scan.nextint ();
Double bonus,bonus10,bonus20,bonus40,bonus60,bonus100,bonusout100;
bonus10=10*0.1;
bonus20=bonus10+10*0.075;
bonus40=bonus20+20*0.05;
bonus60=bonus40+20*0.03;
bonus100=bonus60+40*0.015;
if (i*10000<=100000) {
bonus=i*0.1;
SYSTEM.OUT.PRINTLN ("Total bonus payable:" +bonus+ "million");
}else if (i*10000<=200000) {
bonus=bonus10+ (I-10) *0.075;
SYSTEM.OUT.PRINTLN ("Total bonus payable:" +bonus+ "million");
}else if (i*10000<=400000) {
bonus=bonus20+ (I-20) *0.05;
SYSTEM.OUT.PRINTLN ("Total bonus payable:" +bonus+ "million");
}else if (i*10000<=600000) {
bonus=bonus40+ (I-40) *0.03;
SYSTEM.OUT.PRINTLN ("Total bonus payable:" +bonus+ "million");
}else if (i*10000<=1000000) {
bonus=bonus60+ (I-60) *0.015;
SYSTEM.OUT.PRINTLN ("Total bonus payable:" +bonus+ "million");
}else{
bonus=bonus100+ (I-100) *0.01;
SYSTEM.OUT.PRINTLN ("Total bonus payable:" +bonus+ "million");
}
}
}
Java Fundamentals 03