Update
This commit is contained in:
1 parent
93ba2c358d
commit
acea269f26
22 files changed
+95
-23
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,81 @@
|
||||
package finalexam.Database;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.Scanner;
|
||||
|
||||
import jxl.Workbook;
|
||||
import jxl.write.Label;
|
||||
import jxl.write.WritableSheet;
|
||||
import jxl.write.WritableWorkbook;
|
||||
|
||||
public class DataOutput {
|
||||
private static final String DBDRIVER = "com.mysql.cj.jdbc.Driver";
|
||||
private static final String DBURL = "jdbc:mysql://localhost:3306/xiaoshou?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Class.forName(DBDRIVER);
|
||||
Connection conn = DriverManager.getConnection(DBURL);
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.println("===****超市商品管理维护====");
|
||||
System.out.println("1、导出商品信息至excel");
|
||||
System.out.println("2、导出商品信息至文本文件");
|
||||
System.out.println("3、返回主菜单");
|
||||
System.out.print("请选择(1-3):");
|
||||
int choice = sc.nextInt();
|
||||
switch (choice) {
|
||||
case 1:
|
||||
WritableWorkbook workbook = Workbook.createWorkbook(new File("商品导出.xls"));
|
||||
WritableSheet sheet = workbook.createSheet("商品信息", 0);
|
||||
sheet.addCell(new Label(0, 0, "条码"));
|
||||
sheet.addCell(new Label(1, 0, "名称"));
|
||||
sheet.addCell(new Label(2, 0, "单价"));
|
||||
sheet.addCell(new Label(3, 0, "供应商"));
|
||||
pstmt = conn.prepareStatement("SELECT * FROM t_shangping");
|
||||
rs = pstmt.executeQuery();
|
||||
int row = 1;
|
||||
while (rs.next()) {
|
||||
sheet.addCell(new Label(0, row, rs.getString("tiaoma")));
|
||||
sheet.addCell(new Label(1, row, rs.getString("mingcheng")));
|
||||
sheet.addCell(new Label(2, row, rs.getString("danjia")));
|
||||
sheet.addCell(new Label(3, row, rs.getString("gongyingshang")));
|
||||
row++;
|
||||
}
|
||||
workbook.write();
|
||||
workbook.close();
|
||||
System.out.println("成功导出" + (row - 1) + "条商品数据到excel中");
|
||||
break;
|
||||
case 2:
|
||||
FileWriter fw = new FileWriter("商品导出.txt");
|
||||
BufferedWriter bw = new BufferedWriter(fw);
|
||||
bw.write("条码\t名称\t单价\t供应商\n");
|
||||
pstmt = conn.prepareStatement("SELECT * FROM t_shangping");
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
bw.write(rs.getString("tiaoma") + "\t");
|
||||
bw.write(rs.getString("mingcheng") + "\t");
|
||||
bw.write(rs.getString("danjia") + "\t");
|
||||
bw.write(rs.getString("gongyingshang") + "\n");
|
||||
}
|
||||
bw.close();
|
||||
fw.close();
|
||||
System.out.println("成功导出XXX条商品数据到txt中");
|
||||
break;
|
||||
case 3:
|
||||
break;
|
||||
default:
|
||||
System.out.println("无效的选择,请重新选择(1-3):");
|
||||
break;
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package finalexam.StandardIO;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class DateCalculation {
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String s = sc.nextLine();
|
||||
String[] arr = s.split("[-]");
|
||||
@@ -14,9 +14,8 @@ public class DateCalculation {
|
||||
if (isLeapYear(year))
|
||||
days[2] = 28;
|
||||
int ans = day;
|
||||
for (int i = 1; i < month; i++) {
|
||||
for (int i = 1; i < month; i++)
|
||||
ans += days[i];
|
||||
}
|
||||
System.out.println(ans);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package finalexam.StandardIO;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class DateFormatOutput {
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws Exception {
|
||||
char[] num = { '〇', '一', '二', '三', '四', '五', '六', '七', '八', '九' };
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String s = sc.next();
|
||||
|
||||
@@ -3,7 +3,7 @@ package finalexam.StandardIO;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Encryption {
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws Exception{
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String s = sc.nextLine();
|
||||
String k = sc.nextLine();
|
||||
|
||||
@@ -3,7 +3,7 @@ package finalexam.StandardIO;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Expressions {
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws Exception{
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String s = sc.nextLine();
|
||||
String[] arr = s.split("[\\(\\),]");
|
||||
|
||||
@@ -2,14 +2,12 @@ package finalexam.StandardIO;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class FileIO {
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws Exception {
|
||||
File fQ = new File("question.txt");
|
||||
File fA = new File("answer.txt");
|
||||
try {
|
||||
Scanner sc = new Scanner(fQ);
|
||||
FileWriter fw = new FileWriter(fA);
|
||||
while (sc.hasNextLine()) {
|
||||
@@ -36,8 +34,5 @@ public class FileIO {
|
||||
fw.write(s + "=" + ans + '\n');
|
||||
}
|
||||
fw.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,14 +4,13 @@ import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class PrimeNumbers {
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int n = sc.nextInt();
|
||||
ArrayList<Integer> primes = new ArrayList<>();
|
||||
for (int i = 2; i < n; i++) {
|
||||
for (int i = 2; i < n; i++)
|
||||
if (isPrime(i))
|
||||
primes.add(i);
|
||||
}
|
||||
System.out.print(primes.size() + "(分别是");
|
||||
for (int i = 0; i < primes.size(); i++) {
|
||||
System.out.print(primes.get(i));
|
||||
@@ -24,10 +23,9 @@ public class PrimeNumbers {
|
||||
static boolean isPrime(int n) {
|
||||
if (n <= 1)
|
||||
return false;
|
||||
for (int i = 2; i <= Math.sqrt(n); i++) {
|
||||
for (int i = 2; i <= Math.sqrt(n); i++)
|
||||
if (n % i == 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package finalexam.StandardIO;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class SecurePasswordSpecification {
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String s = sc.next();
|
||||
System.out.println(isSafePassword(s) ? "success" : "fail");
|
||||
|
||||
@@ -33,7 +33,7 @@ class Goods {
|
||||
}
|
||||
|
||||
public class StatisticsOfProducts {
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
Goods[] goods = new Goods[5];
|
||||
double sum = 0;
|
||||
|
||||
@@ -3,17 +3,16 @@ package finalexam.StandardIO;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class StringInitialization {
|
||||
public static void main(String[] var0) {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String s = sc.nextLine();
|
||||
char[] c = s.toCharArray();
|
||||
c[0] = Character.toUpperCase(c[0]);
|
||||
for (int i = 1; i < c.length; i++) {
|
||||
for (int i = 1; i < c.length; i++)
|
||||
if (c[i - 1] != ',' && c[i - 1] != ' ')
|
||||
c[i] = Character.toLowerCase(c[i]);
|
||||
else
|
||||
c[i] = Character.toUpperCase(c[i]);
|
||||
}
|
||||
System.out.println(new String(c));
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package finalexam.StandardIO;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class SumInReverseOrder {
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int n1 = sc.nextInt();
|
||||
int n2 = sc.nextInt();
|
||||
|
||||
Reference in new issue
Block a user