标签:
最近学习时间减少了,这点应该反省.一个星期的时间,学习的东西并不多: 基本数据类型,常量,变量,赋值,操作符,选择语句,循环语句,字符串,再写了一些如计算闰年/计算税率等十分简单的程序 ,这些东西本可以在两三天就学完的.
挂出刚刚写的一个程序 ,这是一个猜数字的小程序.
import java.util.Scanner;
public class GuessNumber
{
public static void main(String[] args)
{
int number = (int)(Math.random()*101);
Scanner input = new Scanner(System.in);
System.out.println("Guess a magic number between 0 and 100");
int Guess = -1;
while (Guess != number)
{
System.out.print("\nEnter your guess:");
Guess = input.nextInt();
if (Guess == number)
System.out.println("yes,the number is" + number);
else if (Guess > number)
System.out.println("You guess is too high");
else
System.out.println("You guess is too low");
}
}
}
继续努力吧.
标签:
原文地址:http://www.cnblogs.com/LatoAndroid/p/5256046.html