java作业5
上机1
public class a {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int i=1,sum=0;
while (i<=100){
if(i%3==0)
sum+=i;
i++;
}
System.out.println("sum="+sum);
}
}
2
int i=0;
while(i<=9){
if(i!=5)
System.out.println(+i);
i++;
}
}
}
3
import java.util.Scanner;
public class a {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new Scanner(System.in);
System.out.println("输入一个数");
int n=input.nextInt();
int sum=1;
int i=1;
while(i<=n)
{
sum*=i;
i++;
}
System.out.println(+sum);
}
4
import java.util.Scanner;
public class a {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new Scanner(System.in);
System.out.println("输入学生成绩");
int n=input.nextInt();
while(n<0||n>100){
System.out.println("输入错误");
n=input.nextInt();
}
}
}
5
import java.util.Scanner;
public class a {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
double sum=30000;
int i=1;
double n=1;
double s=30000;
while(i<10){
n=s*1.06;
s=n;
sum+=s;
i++;
}
System.out.println("10年后的年薪"+s);
System.out.println("10年后的总收入"+sum);
}
}
线下作业
1
import java.util.Scanner;
public class a {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int a=100;
while(a<1000){
int bai=a/100;
int shi=a/10%10;
int ge=a%10;
if(ge*ge*ge+shi*shi*shi+bai*bai*bai==a)
System.out.println(a);
a++;
}
}
}
2
import java.util.Scanner;
public class a {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new Scanner(System.in);
System.out.println("年份");
int year=input.nextInt();
System.out.println("月份");
int month=input.nextInt();
System.out.println("日");
int day=input.nextInt();
int sum=0;
for(int i=1;i<month;i++){
switch(i){
case 4:
case 6:
case 9:
case 11:
sum=sum+30;
break;
case 2:
if(year%4==0&&year%100!=0||year%400==0)
sum=sum+29;
else
sum=sum+28;
break;
default:sum=sum+30;
break;
}
}
sum=sum+day;
System.out.println(year+"年中的第"+sum+"天");
}
}
3
import java.util.Scanner;
public class a {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("输入一个4位数");
int x = input.nextInt();
int a = 1;
int y, b, c, d, e;
b = x % 10;
c = x % 100 / 10;
d = x % 1000 / 100;
e = x / 1000;
for (a = 1; a < 10000; a++) {
if (a / 1000 == b && a % 1000 / 100 == c && a % 100 / 10 == d
&& a % 10 == e) {
y = b * 1000 + c * 100 + d * 10 + e;
System.out.println( + y);
}
}
}
}