欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Java day3

程序员文章站 2022-06-30 19:34:03
目录分支语句–>Random//import java.util.Scanner;//import java.util.Random;import java.util.Random;import java.util.Scanner;public class three{public static void main(String[] arge){//创建对象//Random r=new Random();//用循环获取10个随机数/*...

目录
分支语句–>Random


//import java.util.Scanner;
//import java.util.Random;
import java.util.Random;
import java.util.Scanner;
public class three{
	public static void main(String[] arge){
		
		//创建对象
		//Random r=new Random();
		
		//用循环获取10个随机数
		
		/*
		for(int i=0;i<10;i++){
			//获取随机数
			int number=r.nextInt(10);//获取数据的范围[0,10)
			System.out.println("number:"+number);
		}
		*/
		Random r=new Random();
		//获取1-100之间的随机数
		int number=r.nextInt(100)+1;
		Scanner sc=new Scanner(System.in);
		
		System.out.println("请输入你要猜的数字:");
		while(true){
			int guessNumber=sc.nextInt();
			
			if(guessNumber>number){
				System.out.println("你猜的数字"+guessNumber+"大了");
			}
			else if(guessNumber<number){
				System.out.println("你猜的数字"+guessNumber+"小了");
			}
			else{
				System.out.println("恭喜你猜中了");
				break;
			}
		}
		
		
		//System.out.println(x);
		//System.out.println("开始");
		/*
		Scanner sc=new Scanner(System.in);
		System.out.println("0时0分");
		System.out.println("0时1分");
		System.out.println("0时2分");
		System.out.println("0时3分");
		System.out.println("--------");
		System.out.println("1时0分");
		System.out.println("1时1分");
		System.out.println("1时2分");
		System.out.println("1时3分");
		System.out.println("--------");
		System.out.println("2时0分");
		System.out.println("2时1分");
		System.out.println("2时2分");
		System.out.println("2时3分");
		*/
		
		//循环改进
		/*
		for(int minute=0;minute<4;minute++)
		{
			System.out.println("0时"+minute+"分");
		}
		System.out.println("--------");
		for(int minute=0;minute<4;minute++)
		{
			System.out.println("1时"+minute+"分");
		}
		System.out.println("--------");
		for(int minute=0;minute<4;minute++)
		{
			System.out.println("2时"+minute+"分");
		}
		System.out.println("--------");
		*/
		
		//外循环控制小时的范围,内循环控制分钟的范围
		/*
		for(int hour=0;hour<24;hour++){
			for(int minute=0;minute<60;minute++){
				System.out.println(hour+"时"+minute+"分");
			}
			System.out.println("--------");
		}
		*/
		/*for(int i=1;i<=5;i++)
		{
			if(i%2==0)
			{
				//continue;
				break;
			}
			System.out.println(i);
		}*/
		/*do{
			System.out.println("Hello World");
		}while(true);*/ 
		/*while(true)
		{
			System.out.println("Hello World");
		}*/
		//int k=0;
		/*for(;;){
			System.out.println("Hello World");
		}*/
		//System.out.println(a);
		//System.out.println("----------");
		/*int b=1;
		while(b<3){
			System.out.println("Hello World");
			b++;
		}
		System.out.println(b);*/
		//System.out.println("----------");
		/*int c=1;
		do{
			System.out.println("Hello World");
			c++;
		}while(c<3);
		*/
		
		
		
		
		
		
		
		
		
		
		//System.out.println("请输入一个月数:");
		//int cc=sc.nextInt();
		/*
		double paper=0.1;
		int count=0;
		int zf=8844430;
		while(paper<zf)
		{		
			paper*=2;
			count++;
		}
		System.out.println("折叠"+count+"次");
		*/
		/*
		System.out.println("--------");
		for(int i=100;i<=999;i++){
			int a=i%10;
			int b=i/10%10;
			int c=i/100;
			if(a*a*a+b*b*b+c*c*c==i){
				sum++;
			}
		}System.out.println("水仙花共有"+sum+"个");
		*/
		//System.out.println("1-100之间的偶数和是:"+sum);
		//System.out.println(sum);
		/*
		int month=sc.nextInt();
		//case穿透
		switch(month)
		{
			case 12:
				//System.out.println("冬季");
				//break;
			case 1:
				//System.out.println("冬季");
				//break;
			case 2:
				System.out.println("冬季");
				break;
			case 3:
				//System.out.println("春季");
				//break;
			case 4:
				//System.out.println("春季");
				//break;
			case 5:
				System.out.println("春季");
				break;
			case 6:
				//System.out.println("夏季");
				//break;
			case 7:
				//System.out.println("夏季");
				//break;
			case 8:
				System.out.println("夏季");
				break;
			case 9:
				//System.out.println("秋季");
				//break;
			case 10:
				//System.out.println("秋季");
				//break;
			case 11:
				System.out.println("秋季");
				break;	
			default:
				System.out.println("请输入正确的月数");
				break;
		}
		*/
		/*
		switch(week)
		{
			case 1:
				System.out.println("星期一");
				break;
			case 2:
				System.out.println("星期二");
				break;
			case 3:
				System.out.println("星期三");
				break;
			case 4:
				System.out.println("星期四");
				break;
			case 5:
				System.out.println("星期五");
				break;
			case 6:
				System.out.println("星期六");
				break;
			case 7:
				System.out.println("星期七");
				break;
			default:
				System.out.println("请输入正确的星期数");
				break;
		}
		*/
		//System.out.println("结束");
		
	}
	
}

本文地址:https://blog.csdn.net/qq_45974939/article/details/107382849

相关标签: Java