数据输入输出及结构化程序设计(java)



代码说话,虽然简单,但是“不积跬步,无以至千里。”



/*
从键盘输入三个整数,求出其中的最大值并输出。
*/



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年。






























评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值