zoukankan      html  css  js  c++  java
  • 第一堂课测试——数组

    先第一代代码

     1 package 数组;
     2 import java.util.List;
     3 import java.util.Scanner;
     4 import java.util.*;
     5 import java.util.Scanner;
     6 import java.util.StringTokenizer;
     7 import java.io.BufferedReader;
     8 import java.io.FileOutputStream;
     9 import java.lang.Math;
    10 import java.io.IOException;
    11 public class Int {
    12     
    13     public static void main(String[] args)
    14     {
    15     int[] str=new int[100];//主体
    16     int[] str1=new int [100];//每一个的串值
    17     System.out.println("请输入您要输入的数目:");
    18     int a=0;//总数
    19     Scanner scan=new Scanner(System.in);
    20     a=scan.nextInt();
    21     System.out.println("请输入整型数字:");
    22     for(int i=0;i<a;i++) {
    23         int s1;
    24         s1=scan.nextInt();
    25         str[i]=s1;
    26     }int l=0;
    27     for(int i=0;i<a;i++) {
    28         System.out.println("第"+(i+1)+"个是:"+str[i]);
    29     }
    30     int O=0;
    31     for(int i=0;i<a;i++) {
    32         int i1=i+1;
    33         int o;o=0;
    34         for(int j=i+1;j<a;j++)
    35         {    O=O+1;
    36             int m=str[i]; int n=str[j];
    37             int N=0;int M=0;
    38             o=o+1;
    39             if(o==1) {
    40                 M=n+m;
    41                 str1[O-1]=M;
    42             }
    43             else {
    44                 N=str1[O-2]+n;
    45                 str1[O-1]=N;
    46                 System.out.println(n);
    47             }
    48             System.out.println("数字:"+(O-1)+"   "+str1[O-1]);
    49             l=O;
    50         }
    51     }int max=0;
    52     max=str1[0];
    53     for(int i=0;i<l;i++) {
    54         int m1=0;int m2=0;
    55         m1=str1[i];
    56         m2=str1[i+1];
    57         if(max<m2)max=m2;
    58         if(max<m1)max=m1;
    59     }
    60     if(max<str[0])max=str[0];
    61     if(max<str[a-1])max=str[a-1];
    62     System.out.println(max);
    63     }
    64 }

    由于这个并没有实现O(n)

    然后下一代

     1 package 数组;
     2 
     3 import java.util.Scanner;
     4 
     5 public class Shu {
     6 public static void main(String[] args) {
     7     int[] str=new int[100];
     8     int[] str1=new int[100];
     9     System.out.println("请输入您要输入的数目:");
    10     int a=0;//总数
    11     Scanner scan=new Scanner(System.in);
    12     a=scan.nextInt();
    13     System.out.println("请输入整型数字:");
    14     for(int i=0;i<a;i++) {
    15         int s1;
    16         s1=scan.nextInt();
    17         str[i]=s1;
    18     }int l=0;
    19     for(int i=0;i<a;i++) {
    20         System.out.println("第"+(i+1)+"个是:"+str[i]);
    21     }
    22     int N=-1;//第一个的在数组第几个
    23     for(int i=0;i<a;i++) {
    24         if(str[i]>0) {
    25             N=i;break;
    26         }
    27     }
    28     int max=str[0];//选最大的
    29     if(N==-1) {//如果数组里没有正数(0或者负数)
    30         for(int i=0;i<a;i++) {
    31             if(max<str[i])max=str[i];
    32         }
    33         System.out.println("最大的子数组:"+max);
    34     }
    35     else {
    36         int M=0;//数据块最后一个
    37         int S=0;//判断数据块是正
    38         for(int i=N+1;i<a;i++) {
    39             int j=0;
    40             S=S+str[i];
    41             if(S>0)
    42             {
    43                 M=i;
    44                 str1[j]=S;
    45                 break;
    46             }
    47             j=j+1;
    48         }
    49         if(M==a-1)
    50         {
    51             max=S;
    52             System.out.println("最大的子数组:"+max);
    53         }
    54         
    55         
    56         
    57         
    58         
    59         
    60     }
    61 }
    62 }
  • 相关阅读:
    chrome浏览器中安装以及使用Elasticsearch head 插件
    windows10 升级并安装配置 jmeter5.3
    linux下部署Elasticsearch6.8.1版本的集群
    【Rollo的Python之路】Python 爬虫系统学习 (八) logging模块的使用
    【Rollo的Python之路】Python 爬虫系统学习 (七) Scrapy初识
    【Rollo的Python之路】Python 爬虫系统学习 (六) Selenium 模拟登录
    【Rollo的Python之路】Python 爬虫系统学习 (五) Selenium
    【Rollo的Python之路】Python 爬虫系统学习 (四) XPath学习
    【Rollo的Python之路】Python 爬虫系统学习 (三)
    【Rollo的Python之路】Python sys argv[] 函数用法笔记
  • 原文地址:https://www.cnblogs.com/smartisn/p/10507367.html
Copyright © 2011-2022 走看看