package assignment;
public class Assignment01 {
/**
* @param args
*/
public static void main(String[] args) {
int sum = 0;
for (int n = 1; n <= 100; n++) {
if (n % 10 != 3) {
sum += n;
}
}
System.out.println(sum);
}
}
package assignment;
public class Assignment02 {
/**
* @param args
*/
public static void main(String[] args) {
int starNum = 1;
for (int spaceNum = 3; spaceNum >= 0; spaceNum--) {
for (int n = 0; n < spaceNum; n++) {
System.out.print(" ");
}
for (int n = 0; n < starNum; n++) {
System.out.print("*");
}
starNum += 2;
System.out.println();
}
System.out.println();
for (starNum = 5; starNum > 0; starNum--) {
for (int n = 0; n < starNum; n++) {
System.out.print("*");
}
System.out.println();
}
}
}
package assignment;
import java.util.Scanner;
public class Assignment03 {
/**
* @param args
*/
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
String name = scanner.next();
if (name.equals("Q")) {
System.out.println("done");
break;
}
}
}
}
package assignment;
import java.util.Scanner;
public class Assignment04 {
/**
* @param args
*/
public static void main(String[] args) {
int sum = 0;
int n = 0;
Scanner scanner = new Scanner(System.in);
while (n < 5) {
int grade = scanner.nextInt();
if (grade < 0 || grade > 100) {
System.out.println("invalid input, please input again.");
}
else {
sum += grade;
n++;
}
}
System.out.println(sum);
}
}
package assignment;
public class Assignment05 {
/**
* @param args
*/
public static void main(String[] args) {
double sum = 0;
for (int n = 1; n <= 10; n++) {
int denominator = 0;
// System.out.print("1 / ( ");
for (int m = 1; m <= n; m++) {
// System.out.print(String.valueOf(m) + " + ");
denominator += m;
}
sum += (1.0 / denominator);
// System.out.println(") + ");
}
System.out.println(sum);
}
}
package com.homework06;
import java.util.Random;
import java.util.Scanner;
public class Assignment01 {
public static void main(String[] args) {
Random r = new Random();
int random = r.nextInt(99) + 1;
Scanner scanner = new Scanner(System.in);
int input = scanner.nextInt();
while (random != input) {
if (input < random) {
System.out.println("too small");
}
else {
System.out.println("to big");
}
input = scanner.nextInt();
}
System.out.println("correct");
}
}
package com.homework06;
import java.util.Scanner;
public class Assignment02 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int target = scanner.nextInt();
for (int n = 2; n < target; n++) {
if (target % n == 0) {
System.out.println("不是");
return;
}
}
System.out.println("是");
}
}
package com.homework06;
public class Assignment03 {
public static void main(String[] args) {
int a = 1;
int b = 1;
for (int n = 2; n < 20; n++) {
int t = a;
a = b;
b = a + t;
}
System.out.println(b);
}
}