實訓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.pswp.cn/news/379790.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/379790.shtml
英文地址,請注明出處:http://en.pswp.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…