• 关于

    java i+=

    的搜索结果

回答

import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Scanner; public class LatinArrayHandler { private static int STOP_SIGNAL = 0; private boolean isLatinArray(int stepNum, List<Integer> sourceArray) { Map<Integer, Integer> itemMap = new HashMap<Integer, Integer>(); int firstRowCount = 0; for (int i = 0; i < stepNum; i++) { firstRowCount += sourceArray.get(i); itemMap.put(sourceArray.get(i), sourceArray.get(i)); } if (itemMap.size() != stepNum) { return false; } // System.out.println("firstRowCount=" + firstRowCount); int rowPointer = 0; int colPointer = 0; for (int j = 0; j < stepNum; j++) { // System.out.println("========the [" + j + "] row and col count======"); if (!checkRowNums(stepNum, rowPointer, sourceArray, firstRowCount, itemMap) || !countColNums(stepNum, colPointer, sourceArray, firstRowCount, itemMap)) { return false; } else { rowPointer += stepNum; colPointer++; } } return true; } private boolean checkRowNums(int stepNum, int curPointer, List<Integer> sourceArray, int firstRowCount, Map<Integer, Integer> itemMap) { int rowTotal = 0; for (int i = 0; i < stepNum; i++) { if (!itemMap.containsKey(sourceArray.get(curPointer))) { return false; } else { rowTotal += sourceArray.get(curPointer); curPointer++; } } // System.out.println(" this row total = " + rowTotal); if (rowTotal != firstRowCount) { return false; } return true; } private boolean countColNums(int stepNum, int curPointer, List<Integer> sourceArray, int firstRowCount, Map<Integer, Integer> itemMap) { int colTotal = 0; for (int i = 0; i < stepNum; i++) { if (!itemMap.containsKey(sourceArray.get(curPointer))) { return false; } else { colTotal += sourceArray.get(curPointer); curPointer += stepNum; } } // System.out.println(" this col total = " + colTotal); if (colTotal != firstRowCount) { return false; } return true; } private boolean isStandardLatinArray(int stepNum, List<Integer> sourceArray) { int rowPointer = 0; int colPointer = 0; return isSequenceRow(stepNum, rowPointer, sourceArray) && isSequenceCol(stepNum, colPointer, sourceArray); } private boolean isSequenceRow(int stepNum, int curPointer, List<Integer> sourceArray) { int expectedNum = sourceArray.get(curPointer) + 1; for (int i = 1; i < stepNum; i++) { if (expectedNum != sourceArray.get(i)) { return false; } else { expectedNum++; } } return true; } private boolean isSequenceCol(int stepNum, int curPointer, List<Integer> sourceArray) { int expectedNum = sourceArray.get(curPointer) + 1; for (int i = 1; i < stepNum; i++) { if (expectedNum != sourceArray.get(i)) { return false; } else { expectedNum += stepNum; } } return true; } private void printResult(boolean isLatinArray, boolean isStandardLatinArray) { if (isLatinArray) { if (isStandardLatinArray) { System.out.println(">>>>>checking result == the array is standard latin array == 2"); } else { System.out.println(">>>>>checking result == the array is latin array == 1"); } } else { System.out.println(">>>>>checking result == the array not latin array == 0"); } } public static void main(String[] args) throws IOException { LatinArrayHandler latinArrayHandler = new LatinArrayHandler(); int stepNum = 0; while (true) { System.out.println("===== start the latin array checking==========="); System.out.println("please input the step number>>"); Scanner scanner = new Scanner(new InputStreamReader(System.in)); stepNum = Integer.parseInt(scanner.nextLine()); if (stepNum <= STOP_SIGNAL) { scanner.close(); break; } else { List<Integer> sourceList = new ArrayList<Integer>(); System.out.println("the step number is [" + stepNum + "], please input the array with the format:" + stepNum + " * " + stepNum); for (int i = 0; i < stepNum; i++) { String line = scanner.nextLine(); String[] numsLine = line.split(" "); for (String str : numsLine) { sourceList.add(Integer.parseInt(str)); } } boolean isLatinArray = latinArrayHandler.isLatinArray(stepNum, sourceList); boolean isStandardLatinArray = latinArrayHandler.isStandardLatinArray(stepNum, sourceList); latinArrayHandler.printResult(isLatinArray, isStandardLatinArray); } } System.out.println("===== stopped the latin array checking==========="); } }

蛮大人123 2019-12-02 02:36:50 0 浏览量 回答数 0

问题

java 数插入数组问题

蛮大人123 2019-12-01 20:26:41 1074 浏览量 回答数 1

回答

import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { static boolean foo(String[] arr) { for (int k = 0; k < arr.length; k++) for (int i = 0; i < arr[0].length() - 1; i++) for (int j = i + 1; j < arr[0].length(); j++) { if (arr[k].charAt(i) == arr[k].charAt(j)) return true; } for (int k = 0; k < arr[0].length(); k++) for (int i = 0; i < arr.length - 1; i++) for (int j = i + 1; j < arr.length; j++) if (arr[i].charAt(k) == arr[j].charAt(k)) return true; return false; } public static void main (String[] args) throws java.lang.Exception { // your code goes here String[] arr = new String[3]; arr[0] = "321"; arr[1] = "132"; arr[2] = "212"; boolean b = foo(arr); System.out.println(b); } }

蛮大人123 2019-12-02 02:36:47 0 浏览量 回答数 0

阿里云高校特惠,助力学生创业梦!0元体验,快速入门云计算!

学生动手场景应用,快速了解并掌握云服务器的各种新奇玩法!

问题

关于java越界的问题。

51干警网 2019-12-01 19:41:02 1125 浏览量 回答数 1

回答

public class Util { public String ReadFile(String Path){ BufferedReader reader = null; String laststr = ""; try{ FileInputStream fileInputStream = new FileInputStream(Path); InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8"); reader = new BufferedReader(inputStreamReader); String tempString = null; while((tempString = reader.readLine()) != null){ laststr += tempString; } reader.close(); }catch(IOException e){ e.printStackTrace(); }finally{ if(reader != null){ try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } } return laststr; } } (2)Test.java: import java.util.ArrayList; import java.util.Iterator; import java.util.List; import net.sf.json.JSONArray; import net.sf.json.JSONObject; public class Test { public static void main(String[] args) { // TODO Auto-generated method stub String JsonContext = new Util().ReadFile("D:\\test\\apkinfo.json"); JSONArray jsonArray = JSONArray.fromObject(JsonContext); int size = jsonArray.size(); System.out.println("Size: " + size); for(int i = 0; i < size; i++){ JSONObject jsonObject = jsonArray.getJSONObject(i); System.out.println("[" + i + "]name=" + jsonObject.get("name")); System.out.println("[" + i + "]package_name=" + jsonObject.get("package_name")); System.out.println("[" + i + "]check_version=" + jsonObject.get("check_version")); } } }

蛮大人123 2019-12-02 02:40:45 0 浏览量 回答数 0

问题

java跳出嵌套循环的处理方法

蛮大人123 2019-12-01 19:57:06 930 浏览量 回答数 1

回答

C语言版: #include "stdio.h"// #include "stdlib.h"// void main(void){ int *p,n,s,i,j,k; printf("How many people?\nn="); scanf("%d",&n); if(!(p=(int *)malloc(n*sizeof(int)))){ printf("Application memory failure...\n"); return; } for(i=0;i<n;p[i]=1+i++); printf("Count off to?\ns="); scanf("%d",&s); for(i=j=k=0;;i++){// if(i==n) i=0; if(!p[i]) continue; if(++j==s){ p[i]=j=0; if(++k==n) break; } } printf("The last one is: %d.\n",i+1); free(p); } java语言版 public static void joseph(boolean[] array) { for (int i = 0; i < array.length; i++) { array[i] = true; } int counter = 0;// 计数器 int leftCount = array.length;// 剩余人数 int index = 0;// 索引 while (leftCount > 1) { if (array[index]) { counter++; if (counter == 3) { counter = 0; array[index] = false; leftCount--; } } index++; if (index == array.length) { index = 0; } } for (int i = 0; i < array.length; i++) { if (array[i]) { System.out.println("剩余人员的位置是" + (i + 1)); } } } public static void main(String[] args) { boolean[] array = new boolean[10]; joseph(array); } C++版 #include <iostream> using namespace std; void Solution1(int *arr, int length, int m); int main() { int arr[10] = {0,1,2,3,4,5,6,7,8,9}; int m = 5; Solution1(arr,10,m); return 0; } /* simulate the process */ void Solution1(int *arr, int length, int m){ int i = 0; int index = length; int mIndex = m; while(index>1){ mIndex = m; while(mIndex > 0){ if(arr[i] != -1){ mIndex--; if(mIndex == 0) arr[i] = -1; } i = (i+1)%length; } index--; } for(i=0;i<length;i++) if(arr[i] != -1) cout<<arr[i]; }

a123456678 2019-12-02 02:18:14 0 浏览量 回答数 0

问题

关于越界的问题

蛮大人123 2019-12-01 19:35:52 1025 浏览量 回答数 1

问题

串模式匹配BF算法的java实现

蛮大人123 2019-12-01 19:45:28 929 浏览量 回答数 1

问题

java for循环里的变量反编译出问题

蛮大人123 2019-12-01 20:01:09 1248 浏览量 回答数 1

回答

给你个java的代码你,希望对你有帮助 package standard.system; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.net.URLEncoder; import java.util.Random; public class RSACrypt { private static int _PrivateKey = 32823; // 私钥 private static int _PublicKey = 20643; // 公钥 private static int _Modulus = 29893; // 模数 // 对数字进行加密解密运算,根据key为公钥或是私钥来判断对数字进行加密或解密操作 private static int Crypt(int number, int key) { int mod; int i; int result = 0; try { mod = number * number % _Modulus; if (key % 2 == 0) { result = 1; for (i = 0; i < key / 2; i++) { result = mod * result % _Modulus; } } else { result = number; for (i = 0; i < key / 2; i++) { result = mod * result % _Modulus; } } } catch (Exception e) { } return result; } // 根据字符位置将字符的ASCII数值进行偏移,并得到密文 public static String Encode(String message) { int length = message.length(); // 明文的长度 int ascCode; // ASCII码 int cryptCode; // 密码 int rndCode; // 随机码 int index; String encodeString = ""; // 密文 if (length == 0) { return null; } // 产生随机码 Random rnd = new Random(); rndCode = 1 + rnd.nextInt(99); for (index = 0; index < length; index++) { // 获取单字符的ASCII码 ascCode = (int) message.charAt(index); // 同一字符根据随机码偏移保证每次不同 ascCode += rndCode; // 同一字符在不同位置保证不同 ascCode += index + 1; // 因索引值与domino不同(domino起始为1),所以此处加1 // 同一字符在字符串长度变化时保证不同 ascCode += length; ascCode = ascCode % 128; // 加密为密码 cryptCode = Crypt(ascCode, _PublicKey); // 将密码转换为4位16进制字符串 encodeString += DecimalToHex(cryptCode, 4); } // 最后附上随机码的2位16进制字符串 encodeString += DecimalToHex(rndCode, 2); return encodeString; } // 将密文转换为明文,再对明文进行字位偏移,最终得到原文 public static String Decode(String message) { int length = message.length() - 2; // 剥离随机码后的密文长度 int ascCode; // ASCII码 int cryptCode; // 密码 int rndCode; // 随机码 int index; String decodeString = ""; // 明文 // 获取随机码的10进制数字 rndCode = HexToDecimal(message.substring(length)); for (index = 0; index < length; index += 4) { // 将4位16进制字符串转换为10进制密码 cryptCode = HexToDecimal(message.substring(index, index + 4)); // 解密为明码 ascCode = Crypt(cryptCode, _PrivateKey); // 还原随机码偏移 ascCode -= rndCode; // 还原字位偏移 ascCode += (length / 4 % 128 + 1) * 128 - (index + 1) / 4 - 1; // 因索引值与domino不同(domino起始为1),所以此处加1 // 还原字符串长度偏移 ascCode += (length / 4 % 128 + 1) * 128 - length / 4; ascCode = ascCode % 128; // 将ASCII码转换为字符 decodeString += (char) ascCode; } return decodeString; } // 10进制数字转16进制字符串 private static String DecimalToHex(int decNumber, int hexWidth) { String hexString = Integer.toHexString(decNumber); while (hexString.length() < hexWidth) hexString = "0" + hexString; return hexString; } // 16进制字符串转10进制数字 private static int HexToDecimal(String hexString) { return Integer.parseInt(hexString, 16); } public static void main(String[] args) throws UnsupportedEncodingException { String str = "测试158228&&2008-10-23_15:39:58"; System.out.println(str); str = URLEncoder.encode(str, "UTF-8"); System.out.println(str); for (int i = 0; i < 10; i++) { String r = RSACrypt.Encode(str); System.out.println(r); System.out.println(URLDecoder.decode(RSACrypt.Decode(r), "UTF-8")); } } }

寒凝雪 2019-12-02 01:26:34 0 浏览量 回答数 0

问题

java遍历list问题

蛮大人123 2019-12-01 20:13:41 849 浏览量 回答数 2

回答

import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Random; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class TestPOIP1Title { public static void main(String[] args) throws Exception { String pathname = "E:\\files\\title.xlsx"; File file = new File(pathname); InputStream in = new FileInputStream(file); //得到整个excel对象 XSSFWorkbook excel = new XSSFWorkbook(in); //获取整个excel有多少个sheet int sheets = excel.getNumberOfSheets(); //便利第一个sheet Map<String,String> colMap = new HashMap<String, String>(); for(int i = 0 ; i < sheets ; i++ ){ XSSFSheet sheet = excel.getSheetAt(i); if(sheet == null){ continue; } int mergedRegions = sheet.getNumMergedRegions(); XSSFRow row2 = sheet.getRow(0); Map<Integer,String> category = new HashMap<Integer, String>(); for(int j = 0 ; j < mergedRegions; j++ ){ CellRangeAddress rangeAddress = sheet.getMergedRegion(j); int firstRow = rangeAddress.getFirstColumn(); int lastRow = rangeAddress.getLastColumn(); category.put(rangeAddress.getFirstColumn(), rangeAddress.getLastColumn()+"-"+row2.getCell(firstRow).toString()); } //便利每一行 for( int rowNum = 1 ; rowNum <= sheet.getLastRowNum() ; rowNum++ ){ System.out.println(); XSSFRow row = sheet.getRow(rowNum); if(row == null){ continue; } short lastCellNum = row.getLastCellNum(); String cate = ""; Integer maxIndex = 0; for( int col = row.getFirstCellNum() ; col < lastCellNum ; col++ ){ XSSFCell cell = row.getCell(col); if(cell == null ){ continue; } if("".equals(cell.toString())){ continue; } int columnIndex = cell.getColumnIndex(); String string = category.get(columnIndex); if(string != null && !string.equals("")){ String[] split = string.split("-"); cate = split[1]; maxIndex = Integer.parseInt(split[0]); System.out.println(cate+"<-->"+cell.toString()); }else { //如果当前便利的列编号小于等于合并单元格的结束,说明分类还是上面的分类名称 if(columnIndex<=maxIndex){ System.out.println(cate+"<-->"+cell.toString()); }else { System.out.println("分类未知"+"<-->"+cell.toString()); } } } } } } } 运行的结果如下:

蛮大人123 2019-12-02 01:59:25 0 浏览量 回答数 0

问题

求nextValue数组实现串模式匹配

蛮大人123 2019-12-01 19:47:20 872 浏览量 回答数 1

问题

我在Eclipse中建了几个类,前面几个都还可以运行但建到这个类时不能运行了求解

爵霸 2019-12-01 19:45:08 923 浏览量 回答数 1

回答

import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); String s = sc.nextLine(); char[] s1 = s.toLowerCase().toCharArray(); int[] a = new int[4]; for (int i = 0; i < s1.length; i++) { a[s1[i] - 'a']++; } for (int i = 0; i < 4; i++) { System.out.print(String.valueOf((char)('a' + i)) + a[i] + " "); } } }

蛮大人123 2019-12-02 02:45:52 0 浏览量 回答数 0

回答

用到了Enumeration,代码如下: import java.util.Enumeration; /** * N个要素序列生成,个数为N! */ public class PermEnum implements Enumeration { private int n; private int c[], k; private Object[] objs; public PermEnum(Object[] items) { n = items.length; c = new int[n + 1]; for (int i = 0; i <= n; i++) { c[i] = i; } objs = items; k = 1; } public boolean hasMoreElements() { return k < n; } public Object nextElement() { int i = 0; if ((k & 1) != 0) { i = c[k]; } Object tmp = objs[k]; objs[k] = objs[i]; objs[i] = tmp; k = 1; while (c[k] == 0) { c[k] = k++; } c[k]--; return objs; } // TEST输出 public static void main(String[] args) { String[] strs = {"1", "2", "3", "4"}; // 这里可以自己定义 System.out.println("N=" + strs.length); Enumeration e = new PermEnum(strs); int count = 0; while (e.hasMoreElements()) { String[] a = (String[]) e.nextElement(); System.out.print("[" + a[0]); for (int i = 1; i < a.length; i++) System.out.print(", " + a[i]); System.out.println("]"); count++; } System.out.println("count=" + count); } }

美人迟暮 2019-12-02 01:18:34 0 浏览量 回答数 0

回答

import java.util.Arrays; public class BubbleFinal { public static void main(String[] args) { int[] arr ={25,24,12,76,101,96,28}; sortFinal(arr); } public static void sortFinal(int[] arr) { boolean sorted = true; for (int j = 0; j < arr.length - 1; j++) { sorted = true; System.out.println("第" + (j + 1) + "趟\t"); for (int i = 0; i < arr.length - 1 - j; i++) { if (arr[i] > arr[i + 1]) { int temp = arr[i]; arr[i] = arr[i + 1]; arr[i + 1] = temp; sorted = false; } System.out.println("第" + (i + 1) + "次" + Arrays.toString(arr)); if (sorted) { break; } } } }}

云篆 2019-12-02 01:19:14 0 浏览量 回答数 0

回答

import java.util.Arrays; public class BubbleFinal { public static void main(String[] args) { int[] arr ={25,24,12,76,101,96,28}; sortFinal(arr); } public static void sortFinal(int[] arr) { boolean sorted = true; for (int j = 0; j < arr.length - 1; j++) { sorted = true; System.out.println("第" + (j + 1) + "趟\t"); for (int i = 0; i < arr.length - 1 - j; i++) { if (arr[i] > arr[i + 1]) { int temp = arr[i]; arr[i] = arr[i + 1]; arr[i + 1] = temp; sorted = false; } System.out.println("第" + (i + 1) + "次" + Arrays.toString(arr)); if (sorted) { break; } } } }}

寒凝雪 2019-12-02 01:18:46 0 浏览量 回答数 0

问题

关于Java变量的值以及一个简单的for循环语句

蛮大人123 2019-12-01 19:36:26 841 浏览量 回答数 1

回答

public class TestSort { public static void selectSort(int[] a){ int i; int j; int temp=0; int flag=0; int n=a.length; for(i=0;i<n;i++){ temp=a[ i]; flag=i; for(j=i+1;j<n;j++){ if(a[ j]<temp){ temp=a[ j]; flag=j; } } if(flag!=i){ a[ flag]=a[ i]; a[ i]=temp; } } } public static void main(String[] args) { long i=0; int[] a={10,9,1,4,5,2,8,0,3,7,6}; selectSort(a); for(i=0;i<a.length;i++); System.out.println(a[ i]+""); System.out.println("\n"); } } 这是Java选择排序法

马铭芳 2019-12-02 01:18:39 0 浏览量 回答数 0

回答

import java.util.Stack; public class RailroadWithStacks { // data members private static Stack [] track; // array of holding tracks private static int numberOfCars; private static int numberOfTracks; private static int smallestCar; // smallest car in any holding track private static int itsTrack; // holding track with car smallestCar /** output the smallest car from the holding tracks */ private static void outputFromHoldingTrack() { // remove smallestCar from itsTrack track[itsTrack].pop(); System.out.println("Move car " + smallestCar + " from holding "+ "track " + itsTrack + " to output track"); // find new smallestCar and itsTrack by checking top of all stacks smallestCar = numberOfCars + 2; for (int i = 1; i <= numberOfTracks; i++) if (!track[i].empty() && ((Integer) track[i].peek()).intValue() < smallestCar) { smallestCar = ((Integer) track[i].peek()).intValue(); itsTrack = i; } } /** put car c into a holding track @return false iff there is no feasible holding track for this car */ private static boolean putInHoldingTrack(int c) { // find best holding track for car c // initialize int bestTrack = 0, // best track so far bestTop = numberOfCars + 1; // top car in bestTrack // scan tracks for (int i = 1; i <= numberOfTracks; i++) if (!track[i].empty()) {// track i not empty int topCar = ((Integer) track[i].peek()).intValue(); if (c < topCar && topCar < bestTop) { // track i has smaller car at top bestTop = topCar; bestTrack = i; } } else // track i empty if (bestTrack == 0) bestTrack = i; if (bestTrack == 0) return false; // no feasible track // add c to bestTrack track[bestTrack].push(new Integer(c)); System.out.println("Move car " + c + " from input track "+ "to holding track " + bestTrack); // update smallestCar and itsTrack if needed if (c < smallestCar) { smallestCar = c; itsTrack = bestTrack; } return true; } /** rearrange railroad cars beginning with the initial order inputOrder[1:theNumberOfCars] @return true if successful, false if impossible. */ public static boolean railroad(int [] inputOrder, int theNumberOfCars, int theNumberOfTracks) { numberOfCars = theNumberOfCars; numberOfTracks = theNumberOfTracks; // create stacks track[1:numberOfTracks] for use as holding tracks track = new Stack [numberOfTracks + 1]; for (int i = 1; i <= numberOfTracks; i++) track[i] = new Stack(); int nextCarToOutput = 1; smallestCar = numberOfCars + 1; // no car in holding tracks // rearrange cars for (int i = 1; i <= numberOfCars; i++) if (inputOrder[i] == nextCarToOutput) {// send car inputOrder[i] straight out System.out.println("Move car " + inputOrder[i] + " from input track to output track"); nextCarToOutput++; // output from holding tracks while (smallestCar == nextCarToOutput) { outputFromHoldingTrack(); nextCarToOutput++; } } else // put car inputOrder[i] in a holding track if (!putInHoldingTrack(inputOrder[i])) return false; return true; } /** test program */ public static void main(String [] args) { int [] p = {0, 5, 8, 1, 7, 4, 2, 9, 6, 3}; //int [] p = {0, 3, 6, 9, 2, 4, 7, 1, 8, 5}; System.out.println("Input permutation is 369247185"); railroad(p, 9, 3); } }

蛮大人123 2019-12-02 02:06:44 0 浏览量 回答数 0

问题

java I/O流的问题

蛮大人123 2019-12-01 19:53:27 1081 浏览量 回答数 1

问题

RandomAccessFile无法读取对象后面的数据显示EOFException异常问题

蛮大人123 2019-12-01 20:04:50 1333 浏览量 回答数 1

问题

Java Math.random 执行强制转换引起的问题

蛮大人123 2019-12-01 19:59:25 1018 浏览量 回答数 1

回答

<%@ page language="java" import="java.util.*, java.sql.*" import="java.text.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> * { margin: 0; padding: 0; } body { background: url(0.jpg) no-repeat; background-position: center; margin-top: 30px; height: 500px; } #head { height: 30px; background-color: #D18B00; width: 500px; margin: 0 auto; position: relative; margin-top: 130px; margin-left: 200px; } #table { background-position: center; } <% //到数据库中判断读取出的cookie中的用户名密码是否正确 try { //创建路、人、桶三个对象 Connection conn = null; Statement stmt = null; ResultSet rs = null; //1.加载驱动 Class.forName("com.mysql.jdbc.Driver"); //2.创建连接字符串 String url = "jdbc:mysql://localhost:3306/information"; //3.创建路 conn = DriverManager.getConnection(url, "root", ""); //4.创建人 stmt = conn.createStatement(); //增删改查 //数据库添加、更新、删除数据 //String str1="insert into book values(987,'chen',32.00)"; //String str2="update book set price=50.00 where id=123"; //删除的行数= ID out.print("已经修改的行数为:"); out.print(request.getParameter("ID")); String a = request.getParameter("ID"); String b = request.getParameter("useName"); String c = request.getParameter("password"); out.println("用户名和密码是:"+b); out.println("用户名和密码是:"+c); String str="update user set useName='"+b+"', password='"+c+"' where ID='"+a+"'"; //i代表的是受影响行数 int i = stmt.executeUpdate(str); out.print("受影响行数"+i); if(i==1){ response.sendRedirect("Update.jsp"); } else if(i==0){ response.sendRedirect("Index.jsp"); } } catch (Exception ex) { out.println(ex.toString()); } %>

蛮大人123 2019-12-02 02:38:43 0 浏览量 回答数 0

回答

一、冒泡排序 [java] view plain copy package sort.bubble; import java.util.Random; /** * 依次比较相邻的两个数,将小数放在前面,大数放在后面 * 冒泡排序,具有稳定性 * 时间复杂度为O(n^2) * 不及堆排序,快速排序O(nlogn,底数为2) * @author liangge * */ public class Main { public static void main(String[] args) { Random ran = new Random(); int[] sort = new int[10]; for(int i = 0 ; i < 10 ; i++){ sort[i] = ran.nextInt(50); } System.out.print("排序前的数组为"); for(int i : sort){ System.out.print(i+" "); } buddleSort(sort); System.out.println(); System.out.print("排序后的数组为"); for(int i : sort){ System.out.print(i+" "); } } /** * 冒泡排序 * @param sort */ private static void buddleSort(int[] sort){ for(int i=1;i<sort.length;i++){ for(int j=0;j<sort.length-i;j++){ if(sort[j]>sort[j+1]){ int temp = sort[j+1]; sort[j+1] = sort[j]; sort[j] = temp; } } } } } 二、选择排序 [java] view plain copy package sort.select; import java.util.Random; /** * 选择排序 * 每一趟从待排序的数据元素中选出最小(或最大)的一个元素, * 顺序放在已排好序的数列的最后,直到全部待排序的数据元素排完。 * 选择排序是不稳定的排序方法。 * @author liangge * */ public class Main { public static void main(String[] args) { Random ran = new Random(); int[] sort = new int[10]; for (int i = 0; i < 10; i++) { sort[i] = ran.nextInt(50); } System.out.print("排序前的数组为"); for (int i : sort) { System.out.print(i + " "); } selectSort(sort); System.out.println(); System.out.print("排序后的数组为"); for (int i : sort) { System.out.print(i + " "); } } /** * 选择排序 * @param sort */ private static void selectSort(int[] sort){ for(int i =0;i<sort.length-1;i++){ for(int j = i+1;j<sort.length;j++){ if(sort[j]<sort[i]){ int temp = sort[j]; sort[j] = sort[i]; sort[i] = temp; } } } } } 三、快速排序 [java] view plain copy package sort.quick; /** * 快速排序 通过一趟排序将要排序的数据分割成独立的两部分, 其中一部分的所有数据都比另外一部分的所有数据都要小, * 然后再按此方法对这两部分数据分别进行快速排序, 整个排序过程可以递归进行,以此达到整个数据变成有序序列。 * @author liangge * */ public class Main { public static void main(String[] args) { int[] sort = { 54, 31, 89, 33, 66, 12, 68, 20 }; System.out.print("排序前的数组为:"); for (int data : sort) { System.out.print(data + " "); } System.out.println(); quickSort(sort, 0, sort.length - 1); System.out.print("排序后的数组为:"); for (int data : sort) { System.out.print(data + " "); } } /** * 快速排序 * @param sort 要排序的数组 * @param start 排序的开始座标 * @param end 排序的结束座标 */ public static void quickSort(int[] sort, int start, int end) { // 设置关键数据key为要排序数组的第一个元素, // 即第一趟排序后,key右边的数全部比key大,key左边的数全部比key小 int key = sort[start]; // 设置数组左边的索引,往右移动判断比key大的数 int i = start; // 设置数组右边的索引,往左移动判断比key小的数 int j = end; // 如果左边索引比右边索引小,则还有数据没有排序 while (i < j) { while (sort[j] > key && j > start) { j--; } while (sort[i] < key && i < end) { i++; } if (i < j) { int temp = sort[i]; sort[i] = sort[j]; sort[j] = temp; } } // 如果左边索引比右边索引要大,说明第一次排序完成,将sort[j]与key对换, // 即保持了key左边的数比key小,key右边的数比key大 if (i > j) { int temp = sort[j]; sort[j] = sort[start]; sort[start] = temp; } //递归调用 if (j > start && j < end) { quickSort(sort, start, j - 1); quickSort(sort, j + 1, end); } } } [java] view plain copy /** * 快速排序 * * @param a * @param low * @param high * voidTest */ public static void kuaisuSort(int[] a, int low, int high) { if (low >= high) { return; } if ((high - low) == 1) { if (a[low] > a[high]) { swap(a, low, high); return; } } int key = a[low]; int left = low + 1; int right = high; while (left < right) { while (left < right && left <= high)// 左边向右 { if (a[left] >= key) { break; } left++; } while (right >= left && right > low) { if (a[right] <= key) { break; } right--; } if (left < right) { swap(a, left, right); } } swap(a, low, right); kuaisuSort(a, low, right); kuaisuSort(a, right + 1, high); } 四、插入排序 [java] view plain copy package sort.insert; /** * 直接插入排序 * 将一个数据插入到已经排好序的有序数据中,从而得到一个新的、个数加一的有序数据 * 算法适用于少量数据的排序,时间复杂度为O(n^2)。是稳定的排序方法。 */ import java.util.Random; public class DirectMain { public static void main(String[] args) { Random ran = new Random(); int[] sort = new int[10]; for (int i = 0; i < 10; i++) { sort[i] = ran.nextInt(50); } System.out.print("排序前的数组为"); for (int i : sort) { System.out.print(i + " "); } directInsertSort(sort); System.out.println(); System.out.print("排序后的数组为"); for (int i : sort) { System.out.print(i + " "); } } /** * 直接插入排序 * * @param sort */ private static void directInsertSort(int[] sort) { for (int i = 1; i < sort.length; i++) { int index = i - 1; int temp = sort[i]; while (index >= 0 && sort[index] > temp) { sort[index + 1] = sort[index]; index--; } sort[index + 1] = temp; } } } 顺便添加一份,差不多的 [java] view plain copy public static void charuSort(int[] a) { int len = a.length; for (int i = 1; i < len; i++) { int j; int temp = a[i]; for (j = i; j > 0; j--)//遍历i之前的数字 { //如果之前的数字大于后面的数字,则把大的值赋到后面 if (a[j - 1] > temp) { a[j] = a[j - 1]; } else { break; } } a[j] = temp; } } 把上面整合起来的一份写法: [java] view plain copy /** * 插入排序: * */ public class InsertSort { public void sort(int[] data) { for (int i = 1; i < data.length; i++) { for (int j = i; (j > 0) && (data[j] < data[j - 1]); j--) { swap(data, j, j - 1); } } } private void swap(int[] data, int i, int j) { int temp = data[i]; data[i] = data[j]; data[j] = temp; } } 五、顺便贴个二分搜索法 [java] view plain copy package search.binary; public class Main { public static void main(String[] args) { int[] sort = {1,2,3,4,5,6,7,8,9,10}; int mask = binarySearch(sort,6); System.out.println(mask); } /** * 二分搜索法,返回座标,不存在返回-1 * @param sort * @return */ private static int binarySearch(int[] sort,int data){ if(data<sort[0] || data>sort[sort.length-1]){ return -1; } int begin = 0; int end = sort.length; int mid = (begin+end)/2; while(begin <= end){ mid = (begin+end)/2; if(data > sort[mid]){ begin = mid + 1; }else if(data < sort[mid]){ end = mid - 1; }else{ return mid; } } return -1; } }

知与谁同 2019-12-02 01:19:31 0 浏览量 回答数 0

回答

/** * 利用蒙特卡洛算法(Mente Carlo Method)计算单位圆面积 * */ import java.util.Random; public class MonteCarloMethodTest { public static void main(String[] args) { int sum = 0; int c_sum = 0; double x; double y; Random ra = new Random(); int i = 0; while (i != 100000000) { x = ra.nextDouble(); y = ra.nextDouble(); if (x * x + y * y <= 1) ++c_sum; ++sum; ++i; } double area = (double)c_sum / sum * 4; System.out.println("area = " + area); } }

蛮大人123 2019-12-02 02:13:55 0 浏览量 回答数 0

问题

Java编写九九乘法表

爵霸 2019-12-01 19:39:01 702 浏览量 回答数 1

问题

关于java中消除数组中的重复值的问题

蛮大人123 2019-12-01 19:47:40 872 浏览量 回答数 1
阿里云大学 云服务器ECS com域名 网站域名whois查询 开发者平台 小程序定制 小程序开发 国内短信套餐包 开发者技术与产品 云数据库 图像识别 开发者问答 阿里云建站 阿里云备案 云市场 万网 阿里云帮助文档 免费套餐 开发者工具 企业信息查询 小程序开发制作 视频内容分析 企业网站制作 视频集锦 代理记账服务 企业建站模板