小白的java学习日记(三)

一、循环

1.循环
package hello;

import java.io.InputStream;
import java.util.Scanner;

public class Helloworld {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int balance = 0;
		while (true) 
		{	
			System.out.print("请投币:");
			int amount =in.nextInt();
			balance = balance+amount;
			if (balance>=10) {
				System.out.println("#########");
				System.out.println("##购票成功##");
				System.out.println("########");
				System.out.print("找零:"+(balance-10));
				balance = 0;
			}
//			else {
//				System.out.println("抱歉,余额不足");
//			}
		}
	}
}



2.数数字

(1)设计计算机算法时往往将 计算机擅长怎么做事情和人是怎么做事情可不可以让计算机模拟人的行为 两方面结合。通常让计算机模拟人的行为设计出的算法都是比价朴素的算法,如果能够充分利用计算机的特点而设计出来的算法就会说是比较高档一点的算法。
(2)

package hello;

import java.io.InputStream;
import java.util.Scanner;

public class Helloworld {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in)	;
		int number = in.nextInt();
		int count = 0;
		while ( number>0) {
			number = number/10;
			count = count+1;
		}
		System.out.println(count);
	}
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值