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: loop) int i, a = 0;
public class zxcvbn {
public static void main(String[] args) {
for (i = 1; i <= 100; i++) {
if (i % 3 == 0)
a = a + i;
}
System.out.println(a);
}
{
int i = 1, a = 0;
while (i < 101) {
if (i % 3 == 0) {
a = a + i;
}
i++;
}
System.out.println(a);
}
//do while部分
{
int i = 0, a = 0;
do {
if (i % 3 == 0) {
a = a + i;
}
i++;
} while (i < 101);
System.out.println(a);
}
}
}
2. Output a number between 0-9, but does not include 5. (Knowledge Point: condition, loop)
public class zxcvbn {
public static void main(String[] args) {
for(int i=0;i<10;i++)
{
if(i==5)
{
continue;
}
System.out.println(i);
}
}
}
3. Write a program, find the integer n factorial, for example, 5 factorial is 1 * 2 * 3 * 4 * 5 (knowledge: loop)
java.util.Scanner Import;
public class zxcvbn {
public static void main (String [] args) {
int = SUM. 1;
Scanner Scanner new new SC = (the System.in);
System.out.println ( "Please enter an integer: ");
int sc.nextInt K = ();
for (int I =. 1; I <= K; I ++) {
SUM = SUM * I;
}
System.out.println (K +" factorial is: "+ 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)
java.util.Scanner Import;
public class zxcvbn {
public static void main (String [] args) {
System.out.println ( "Please enter student achievement:");
Scanner sc = new new Scanner (System.in);
Double = sc.nextDouble CJ ();
IF (CJ> 100 || CJ <0) {
System.out.println ( "input error, re-enter!");
}
the else {
the System.out .println ( "entered correctly!" );
}
}
}
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)
import java.util.Scanner;
public class zxcvbn {
public static void main(String[] args) {
double x = 30000;
double sum=30000;
for(int i=2;i<11;i++){
x = x *(1+0.06);
sum =sum + x;
}
System.out.println("第10年的年薪为"+sum);
}
}