代码说话,虽然简单,但是“不积跬步,无以至千里。”
/*
从键盘输入三个整数,求出其中的最大值并输出。
*/
import java.util.Scanner;
public class exam1{
public static void main(String []args){
int a,b,c;
int temp;
while(true){
Scanner sc = new Scanner(System.in);
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
temp = a>b ?a:b;
int max = temp>c ?temp:c;
System.out.println("-------------------------------");
System.out.println("最大值:"+max);
}
}
}
//输出九九乘法表。
public class exam2{
public static void main(String []args){
for(int i=1;i<=9;i++){
for(int j=1;j<=i;j++){
if(j==1) System.out.println();
System.out.print(i +"*"+ j +"="+ i*j+" ");
}
}
}
}
运行结果:
//输出1到1000之间,所有可以被3整除又可以被7整除的数。
public class exam3{
public static void main(String []args){
System.out.println("能被3何7整除的数有:");
for(int i=1;i<=1000;i++){
if(i%3==0 && i%7==0)
System.out.print(" "+i);
}
}
}
//找出2~999之间所有的同构数。所谓同构数是指该数出现在它的平方数的右边。如5、6、25等。
public class exam4{
public static void main(String []args){
int num;
int weishu = 0;
for(int i=2;i<1000;i++){
num=i*i;
if(i>2 && i<10)
weishu=num%10;
if(i>=10 && i<100)
weishu=num%100;
if(i>=100 && i<1000)
weishu=num%1000;
if(i == weishu)
System.out.println("同构是有:"+i);
}
}
}
运行结果:
/*
* 我国现有人口为13亿,设年增长率为1%,编写程序,计算多少年后增加到20亿。
*
*/
public class exam5 {
public static void main(String []args){
int a = 0;
double x =13.0;
while(x < 20){
x= x * 1.01;
a++;
}
System.out.println(a+"年");
}
}
运行结果:44年。