1. They were used for loops, while loops, do require that all cycles can be an integer divisible by 3 and between 1 and 100. (Knowledge Point: Loops)
package doom3; public class thefourweekworks1_0 { public static void main(String[] args) { // TODO Auto-generated method stub int i=1; for(i=1;i<=100;i++){ if(i%3==0) System.out.print(" "+i+" "); } } }
package doom3; public class thefourweekworks1_1 { public static void main(String[] args) { // TODO Auto-generated method stub int i=1; while(i<=100){ if(i%3==0) System.out.print(" "+i+" "); i++; } } }
package doom3; public class thefourweekworks1_2 { public static void main(String[] args) { // TODO Auto-generated method stub int i = 1; do { if (i % 3 == 0) System.out.print(" " + i + " "); i++; } while (i <= 100); } }
2. Output a number between 0-9, but does not include 5. (Knowledge Point: condition, loop)
package doom3; public class thefourweekworks2 { public static void main(String[] args) { // TODO Auto-generated method stub int i=0; for(i=0;i<10;i++){ if(i==5) continue; System.out.print(" "+i+" "); } } }
3. Write a program, find the integer n factorial, for example, 5 factorial is 1 * 2 * 3 * 4 * 5 (knowledge: loop)
package doom3; import java.util.Scanner; public class thefourweekworks3 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); System.out.print("请输入一个数字:"); int n = input.nextInt(); int i = 1; int sum = 1; for (i = 1; i <= n; i++) { sum *= i; } System.out.println(sum); } }
4. Write a program, enter any student achievement, if the input is not legitimate (<0 or> 100), suggesting that input errors, re-enter until the input end of the legal procedure (knowledge: Loops)
Doom3 Package; Import java.util.Scanner; public class thefourweekworks4 { public static void main (String [] args) { // the TODO Auto-Generated Method Stub Scanner Scanner new new INPUT = (the System.in); of System.out.print ( "Please enter a student's achievement:"); int i = input.nextInt (); the while (i <0 || i> 100) { System.out.print ( "enter your achievements have questions, please re-enter : "); i = input.nextInt (); } System.out.print (" enter your classmates score: "+ i); } }
5. Suppose a staff this year's annual salary is 30,000 yuan, the annual salary of the annual growth rate of 6%. Write a Java application to calculate the employee's annual salary after 10 years, and counting the next 10 years (counting from the year) of total income. (Knowledge Point: Loops)
Doom3 Package; public class thefourweekworks5 { public static void main (String [] args) { // the TODO Auto-Generated Method Stub int I = 0; Double n-= 30000; Double n-COUNT =; for (I = 0; I <= . 9; I ++) { n-n-* = 1.06; COUNT = COUNT + n-; } System.out.println ( "10 years after the employee's salary:" n-+); System.out.println ( "the employee 10 years total income: "COUNT +); } }