package assignment;
public class Assignment01 {
/**
* @param args
*/
public static void main(String[] args) {
int sum = 0;
int n = 0;
for (n = 3; n <= 100; n += 3) {
sum += n;
}
System.out.println(sum);
sum = 0;
n = 3;
while (n <= 100) {
sum += n;
n += 3;
}
System.out.println(sum);
sum = 0;
n = 3;
do {
sum += n;
n += 3;
} while (n <= 100);
System.out.println(sum);
}
}
package assignment;
public class Assignment02 {
/**
* @param args
*/
public static void main(String[] args) {
for (int n = 0; n < 10; n++) {
if (n != 5) {
System.out.println(n);
}
}
}
}
package assignment;
public class Assignment03 {
/**
* @param args
*/
public static void main(String[] args) {
int target = 5;
if (target < 0) {
System.out.println("invalid target");
return;
}
int sum = 1;
for (int n = target; n >= 2; n--) {
sum *= n;
}
System.out.println(sum);
}
}
package assignment;
import java.util.Scanner;
public class Assignment04 {
/**
* @param args
*/
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
float grade = s.nextFloat();
while (grade < 0 || grade > 100) {
System.out.println("输入错误,请重新输入");
grade = s.nextFloat();
}
System.out.println("输入成绩" + grade);
}
}
package assignment;
public class Assignment05 {
/**
* @param args
*/
public static void main(String[] args) {
float salary = 30000.0f;
float total = 0;
for (int n = 0; n < 10; n++) {
total += salary;
salary *= 1.06;
}
System.out.println(salary);
System.out.println(total);
}
}
package assignment;
public class Assignment06 {
/**
* @param args
*/
public static void main(String[] args) {
int n0 = 0;
int n1 = 0;
int n2 = 0;
for (int target = 100; target <= 999; target++) {
n0 = target % 10;
n1 = target / 10 % 10;
n2 = target / 100;
if ((n0 * n0 * n0 + n1 * n1 * n1 + n2 * n2 * n2) == target) {
System.out.println(target);
}
}
}
}
package com.homework05;
import java.util.Scanner;
public class Assignment02 {
public static void main(String[] args) {
int year;
int month;
int day;
Scanner s = new Scanner(System.in);
year = s.nextInt();
month = s.nextInt();
day = s.nextInt();
if (year < 1) {
System.out.println("invalid year");
return;
}
boolean leap = (year % 100 != 0 && year % 4 == 0 || year % 400 == 0);
if (month < 0 || month >= 12) {
System.out.println("invalid month");
return;
}
if (day < 0) {
System.out.println("invalid day");
}
else {
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
if (month > 31) {
System.out.println("invalid day");
}
}
else if (month == 4 || month == 6 || month == 9 || month == 11) {
if (month > 30) {
System.out.println("invalid day");
}
}
else if (month == 2) {
if (leap) {
if (day > 29) {
System.out.println("invalid day");
}
}
else {
if (day > 28) {
System.out.println("invalid day");
}
}
}
}
int total = 0;
for (int m = 1; m < month; m++) {
if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) {
total += 31;
}
else if (m == 2) {
if (leap) {
total += 29;
}
else {
total += 28;
}
}
else {
total += 30;
}
}
total += day;
System.out.println(total);
}
}
package assignment;
import java.util.Scanner;
public class Assignment08 {
/**
* @param args
*/
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int target = s.nextInt();
if (target < 1000 || target >= 10000) {
System.out.println("invalid target");
}
int result = 0;
int r = 1000;
for (int n = 0; n < 4; n++) {
result += (r * (target % 10));
r /= 10;
target /= 10;
}
System.out.println(result);
}
}