实训09.08:简单的算法练习

        /*final 关键字 修饰的变量值 后期不可更改 相当于定义常量常量 :不可更改*/final int a = 10;//a = 20;       报错的值不可更改!/*输入函数* */System.out.println("请输入数字:");Scanner  scanner = new Scanner(System.in);int b  = scanner.nextInt();     //需要一个变量来承接 System.out.println(b);String name = scanner.next();       //字符串System.out.println("请输入年份:");int year = scanner.nextInt();if((year % 4 == 0 && year %100 != 0) || year % 400 ==0) {System.out.println(year + "是闰年");}else {System.out.println(year + "是平年");}System.out.println("请输入月份:");int moon = scanner.nextInt();if(moon<0 || moon >12) {System.out.println("输入错误!");return;}else if(moon == 1 || moon ==3 || moon == 5 ||moon == 7 || moon ==8|| moon ==10 || moon ==12) {System.out.println(moon + "月有31天");}else if (moon){}//随机数   Random系统的提供的类,用于获取一个随机自然数//(大范围 - 小范围 + 1) + 小范围Random  random = new Random();
//      int num = random.nextInt(100);      0 ~ 100
//      int num = random.nextInt() % 100;       -99 ~ 99int num = random.nextInt(40 - 20 + 1)  + 20;System.out.println(num);//      for(int i = 1;i <= 100; i++) {
//          if(i % 2 != 0) {
//              System.out.println(i);
//          }
//      }//      int sum = 0;
//      for (int i = 1; i <= 100; i++) {
//          sum += i;
//      }
//      System.out.println(sum);//      for(int i = 0;i <= 100; i++) {
//          if(i % 7 == 0) {
//              System.out.println(i);
//          }
//      }//      for (int i = 1;i <= 100;i++) {
//          if(i % 10 == 7 ) {
//              System.out.println(i);
//          }
//      }//      for (int i = 1;i <= 100; i++) {
//           if(i /10 == 7) {
//               System.out.println(i);
//           }
//      }//      for (int i = 1;i<= 100;i++) {
//          if(i / 7 != 0 && i % 10 != 7) {
//              System.out.println(i);
//          }
//      }int min = 100, max = 0;for(int i = 1 ;i <= 10;i++) {
//          int num2 = random.nextInt(80 - 30 + 1)  + 30;int temp =  random.nextInt(51) + 30;if(temp > max) {max = temp;}  if(temp < min) {min = temp;}System.out.print(temp + "    ");}System.out.println("最大值为:" + max  + ";最小值为 :"+min);//练习1for(int i = 1;i < 4;i ++) {for(int j = 1 ;j <= i +1; j++) {System.out.print(j + "      ");}System.out.println();}       System.out.println("---------------------");//练习2for(int i = 0 ;i < 4; i++) {for(int j =1; j <= 4 - i; j++) {System.out.print(j + "      ");}System.out.println();}System.out.println("---------------------");//练习3for(int i = 0;i < 4;i++) {for(int j = 4; j >= i + 1; j--) {System.out.print(j + "   ");}System.out.println();}System.out.println("---------------------");    //练习4for(int i = 1;i <= 9; i++) {for(int j = 1; j <= i; j ++) {System.out.print(j + " * " + i + " = " + i * j);}System.out.println();}//while循环//练习1int  money = 1000000000;int day = 0;while(money != 0) {money /=2;day ++;}System.out.println("一共花了" + day  + "天");}// 数组//eg : 32字节
//      int[]  a1 = {11, 22, 44, 33, 55, 77, 66};
//      a1[0] = 100;
//      int[] a2 = new int [10];    //0 0 0 0 0 0 0 0 0 0 
//      
//      
//      for(int i = 0;i < a1.length;i++) {
//          System.out.println(a1[i]  + "     ");
//      }
//      Randon random= new Random();//练习1Random random = new Random();
/*      int[]  a1 =  new int[10];int[] a2 = new int [10];        for(int i = 0 ;i < 10; i++) {   a1[i] = random.nextInt(41) + 30;a2[i] = a1[i];System.out.println(a1[i]  + "     "  + a2[i]);}
*///练习2
/*      int[] arr1 = new int[5];int[] arr2 = new int[5];int[] arr = new int[10];for(int i = 0 ;i < 5; i ++) {arr1[i] = random.nextInt(41) +50;}
*///练习3int min = 100, minIndex = 0;    //存储下标int max = 0,maxIndex = 0;int[] array1 = new int [10];for(int i =0; i < 10;i ++) {array1[i] = random.nextInt(41) +  10;if(array1[i] < min) {minIndex = i;min = array1[i] ;} if(array1[i] > max) {maxIndex = i;max = array1[i];}System.out.print(array1[i] + "       ");}   System.out.println();System.out.println(min + "下标为: " + minIndex);System.out.println(max + "下标为:" + maxIndex);//二维数组  本质有多个一维数组组成//二位数组的length只能获取行数int[][] m = {{1,2,3,4},{11,22,33,44},{111,222,333,444}};System.out.println(m[1][3]);
package yb;import java.util.Scanner;public class beyond {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入一个年份,谢谢合作!");int wsq= sc.nextInt();if((wsq%4==0 && wsq%100 !=0)   ||   wsq%400 ==0) {System.out.println("好了,你可以上天了。");System.out.println("请输入一个月份");int yy = sc.nextInt();if(yy==1 || yy==3 || yy==5 || yy==7 || yy==8 || yy==10 || yy==12) {System.out.println("31天");}else if(yy==2) {System.out.println("30天");}else {System.out.println("28天");}}else {System.out.println("就你,还想上天?");System.out.println("请输入一个月份");int yy = sc.nextInt();if(yy==1 || yy==3 || yy==5 || yy==7 || yy==8 || yy==10 || yy==12) {System.out.println("31天");}else if(yy==2) {System.out.println("30天");}else {System.out.println("29天");}}}package yb;import java.util.Random;public class CircleFor {public static void main(String[] args) {// Random/** Random random = new Random(); int a = random.nextInt(41)+30;*/// System.out.println(a);/** for(int i=1; i<=100;i=i+2) { System.out.println(i); }*//** int sum = 0; for (int i = 1; i <= 100; i++) { sum = sum + i; }* * System.out.println(sum);* * for (int j = 1; j <= 100; j++) { if (j % 7 == 0) System.out.print(j + " "); }* System.out.println();* * for (int j = 1; j <= 100; j++) { if (j % 10 == 7) System.out.print(j + " ");* } System.out.println();* * for (int k = 1; k <= 100; k++) { if (k / 10 == 7) System.out.print(k + " ");* } System.out.println();* * for (int o = 1; o <= 100; o++) { if ((o % 10 != 7) && (o % 10 != 7) && (o /* 10 != 7)) System.out.print(o + " "); } System.out.println();* * int x[] = new int[10]; Random random = new Random();* * for (int y = 0; y < 10; y++) { x[y] = random.nextInt(51) + 30; }* * for (int i = 0; i < 10; i++) { for (int j = 0; j < 10 - i; j++) { if (x[j] >* x[j + 1]) { int t = x[j]; x[j] = x[j + 1]; x[j + 1] = t; } } }* * for(int j =0;j<10;j++) { System.out.println(x[j]); }* * int max = 0, min = 10; for (int i = 1; i <= 100; i++) { int q =* random.nextInt(51) + 30; if (q > max) max = q; if (q < min) min = q; }* System.out.println(max + " " + min);*/for (int i = 1; i <= 4; i++) {for (int j = 1; j <= i; j++) {System.out.print(j + " ");}System.out.println();}System.out.println("-------------------------------------------------------------------------------------------");for (int j = 4; j >= 1; j--) {for (int k = 1; k <= j; k++) {System.out.print(k + " ");}System.out.println();}System.out.println("--------------------------------------------------------------------------------------------");for (int i = 4; i >= 1; i--) {for (int k = 4; k >= i; k--) {System.out.print(k + " ");}System.out.println();}System.out.println("--------------------------------------------------------------------------------------------");for (int i = 1; i <= 9; i++) {for (int j = 1; j <= i; j++) {System.out.print(i + "*" + j + "=" + j * i + " ");}System.out.println();}System.out.println("--------------------------------------------------------------------------------------------");int y = 0;double p = 1000000000;while (p > 0) {p = p / 2;y++;}System.out.println(y);}}}package yb;import java.util.Scanner;public class days {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int a,b,c,i,j;int sum1=0,sum2=0;int [] y = {0,31,28,31,30,31,30,31,31,30,31,30,31};int [] u = {0,31,29,31,30,31,30,31,31,30,31,30,31};System.out.println("请输入年份:");a = sc.nextInt();if((a%4==0 && a%100 !=0) || a%400 ==0) {System.out.println("请输入一个月份");b = sc.nextInt();System.out.println("請輸入一天數");c = sc.nextInt();for(i=1;i<=b;i++) {sum1 = sum1 + y[i];}System.out.println(sum1+c);}else {System.out.println("请输入一个月份");b = sc.nextInt();System.out.println("請輸入一天數");c = sc.nextInt();for(i=1;i<=b;i++) {sum1 = sum1 + u[i];}System.out.println(sum1+c);}}}
package java02;import java.util.Scanner;public class section {public static void main(String[] args) {String [][] arr = new String [100][2];Scanner wsq= new Scanner(System.in);System.out.println("请输入人数:");int pp = wsq.nextInt();for(int i=0;i<pp;i++) {for(int j=0;j<pp;j++) {System.out.println("请输入账号:");String zh = wsq.next();arr[i][0] = zh;if(arr[i][0].equals(arr[i+1][0]))j--;else break;}boolean yy = true;while(yy) {System.out.println("请输入密码:");String mm = wsq.next();System.out.println("请再次输入密码:");String zmm = wsq.next();if(mm.equals(zmm)) {System.out.println("很好!干得漂亮!");arr[pp][1] = zmm;break;}else {System.out.println("两次密码不一致!!!");}}}for(int i=0 ; i<pp;i++) {for(int j=0;j<2;j++) {System.out.print(arr[i][j] + " ");}System.out.println();}}}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/379790.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

让自己闪亮

转载于:https://www.cnblogs.com/Gigabyte/archive/2009/01/03/you_can_shine.html

Java中的wait()和sleep()方法之间的区别

Java中的wait()和sleep()方法 (wait() and sleep() methods in Java) First, we will see how wait() method differs from sleep() method in Java? 首先&#xff0c;我们将看到wait()方法与Java中的sleep()方法有何不同&#xff1f; wait()方法 (wait() Method) This metho…

离线使用iPhone SDK文档的方法

在使用Xcode进行iPhone编程时&#xff0c;有时需要参考iPhone SDK的文档&#xff0c;不过每次ControlClick后&#xff0c;Xcode都会试图连接Internet&#xff0c;进行在线读取。有什么方法能够把资料下载到硬盘上进行离线阅读吗&#xff1f; 答案是肯定的。首先去Xcode的Prefer…

远程连接sql server 2000服务器的解决方案

远程连接sql server 2000服务器的解决方案2007-04-07 11:29远程连接sql server 2000服务器的解决方案   一 看ping 服务器IP能否ping通。   这个实际上是看和远程sql server 2000服务器的物理连接是否存在。如果不行&#xff0c;请检查网络&#xff0c;查看配置&#xff0c…

实训09.10:HTML简单表格设计

<!DOCTYPE html> <html><head><meta charset"UTF-8"><title>燕雨简历</title></head><body><table border"" cellspacing"" cellpadding"" width"400px" height"6…

LCD显示实验----STM32f4--HAL

步骤 LCD初始化 LCD_Init(); //LCD初始化此函数在lcd.c文件里面 2. 设置LCD背景颜色 LCD_Clear(WHITE);此函数在lcd.c文件里面 3. 设置字体颜色 POINT_COLORRED; 写入要显示的字体 LCD_ShowString(10,80,240,24,24,"LTDC TEST");LCD_ShowSt…

JavaScript | 使用提示从用户输入值

Example 1) Input name and print 示例1)输入名称和打印 Code (JS & HTML): 代码(JS和HTML)&#xff1a; <!DOCTYPE html><HTML><HEAD><SCRIPT>var name prompt("Enter Your name:");var msg "Welcome "name;//alert(msg)…

一个游戏程序员的学习资料 (zz)

一个游戏程序员的学习资料//z 2012-4-19 14:39:51 PM IS2120CSDN想起写这篇文章是在看侯杰先生的《深入浅出MFC》时, 突然觉得自己在大学这几年关于游戏编程方面还算是有些心得&#xff0c;因此写出这篇小文,介绍我眼中的游戏程序 员的书单与源代码参考。一则是作为自己今后两年…

项目管理中工作分解结构模型(WBSM)的应用

摘要 本文根据工作分解结构(WBS)的工作特点&#xff0c;运用系统工程的思想理论方法&#xff0c;构建了工作分解结构模型&#xff0c;并提出了模型算法;该模型方法的建立使得WBS工作更加简单可靠、思路清晰、基于更加可靠的科学基础之上。 1、工作分解结构模型(WBSM)方法工作程…

实训09.11:java重点内容介绍

package test;/** * OP:面向对象的简称* 类&#xff1a;同一特征的属性* * 类的定义&#xff1a;具有相同特征和行为的事物的抽象。&#xff08;不具体化&#xff09;* 对象&#xff08;实例对象&#xff09;&#xff1a;具体真实存在的实例。* 类是对象的实例&#xff1a;* *…

SPI通信原理---STM32F4--HAL

SPI接口原理 SPI是一种高速全双工同步通信&#xff0c;在芯片管脚上占用四根线&#xff0c;主要应用在EEPROM、FLASH、实时时钟、AD转换器&#xff0c;还有数字信号处理器和数字信号解码器之间。 SPI接口使用4根线通信。 MISO&#xff1a;主设备数据输入&#xff0c;从设备数…

Linux 引导管理器 grub2 使用简介

转自&#xff1a;杜昌彬的空间 首先向其致敬&#xff01;有改动。 grub是Linux系统即其他类unix系统的主流bootloder&#xff0c;由于grub原来版本的设计存在很大缺陷&#xff0c;与以前的grub很不相同&#xff0c;其使用和配置也发生很大变化。现在很多Linux发行版本都使用了…

pata1015_ATA / PATA的完整形式是什么?

pata1015ATA / PATA&#xff1a;高级技术附件/并行高级技术附件 (ATA/PATA: Advanced Technology Attachment/Parallel Advanced Technology Attachment) ATA is an abbreviation of Advanced Technology Attachment. ATA has existed for a long time with the name PATA. Whe…

产品

总结一下&#xff1a;  1、核心功能要做透&#xff0c;做的人家追不上&#xff0c;自己的优势要尽量的发挥&#xff1b;  2、产品口碑要建立&#xff0c;要关注高端用户&#xff0c;要调整自己心态&#xff1b;  3、敏捷、快&#xff0c;产品迭代要快&#xff0c;快速实现…

FreeRTOS在STM32F429上移植

准备工作 FreeRTOS系统源码基础工程&#xff0c;这里我们用跑马灯实验 1.在工程里面添加FreeRTOS源码 在工程里面新建一个名为FreeROTS的文件夹 将FreeRTOS源码添加到这个文件夹里面 protable里面只需留下Keil、MemMang、RVDS文件夹 2、向工程分组中添加文件 FreeRTOS_C…

C++中的指针与引用(转)

原文地址&#xff1a;http://www.cnblogs.com/skynet/archive/2010/09/22/1832911.html写在前面 指针和引用形式上很好区别&#xff0c;但是他们似乎有相同的功能,都能够直接引用对象&#xff0c;对其进行直接的操作。但是什么时候使用指针&#xff1f;什么时候使用引用呢&…

实训09.11:数据库一些简单操作

new Database 新建数据库 new Table 新建表 utf-8 编码格式 primary key 主键&#xff1a;特点&#xff1a;在表中是唯一的不可重复的&#xff0c;一般都是学号&#xff0c;编号 auto increment 自增&#xff0c;一般都把主键设置为自增 allow nul…

c语言中将整数转换成字符串_在C语言中将ASCII字符串(char [])转换为八进制字符串(char [])...

c语言中将整数转换成字符串Given an ASCII string (char[]) and we have to convert it into octal string (char[]) in C. 给定一个ASCII字符串(char [])&#xff0c;我们必须在C中将其转换为八进制字符串(char [])。 Logic: 逻辑&#xff1a; To convert an ASCII string t…

Javascript的IE和Firefox兼容性汇编收藏.txt

document.form.item 问题 现有问题&#xff1a;现有代码中存在许多 document.formName.item("itemName") 这样的语句&#xff0c;不能在 MF 下运行 解决方法&#xff1a;改用 document.formName.elements["elementName"] 集合类对象问题 现有问题&#xff…

FreeRTOS系统配置文件FreeRTOSConfig.h

实际使用FreeRTOS的时候&#xff0c;我们时常需要根据自己需求来配置FreeRTOS&#xff0c;而且不同架构的MCU在使用的时候配置也不同&#xff0c;FreeRTOS的系统配置文件FreeRTOSConfig.h可以完成FreeRTOS的裁剪和配置。FreeRTOSConfig.h分成两个部分&#xff0c;一个是INCLUDE…