入门java要多少代码 入门java要多少代码合适( 三 )


str=str.trim();
}catch(Exception ex)
{System.out.println("出错啦笨蛋");}
return str;
}
}
//将键盘输入的字符转换为数字
class zhuanhuan
{
private int a;
public int zhuanhuan1(String str)
{
try{
a=Integer.parseInt(str);
return a;
}catch(Exception ex){return -1;}
}
}
class baocun
{
public int charu(String name,int point,int nandu)
{
int a=-1;
String sql;
Connection con=null;
PreparedStatement ps=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:caishuzi");
sql="insert into user(uname,cishu,nandu) values(?,?,?)";
ps = con.prepareStatement(sql);
ps.setString(1, name);
ps.setInt(2, point);
ps.setInt(3, nandu);
a=ps.executeUpdate();
//System.out.println("aaaaaaa");
ps.close();
con.close();
}catch(Exception ex)
{System.out.println("储存出错啦!");
ex.printStackTrace();
}
return a;
}
}
哪位高手帮写个JAVA入门小程序,估计就几十行代码//第一题:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.ArrayList;
import java.util.List;
public class ManageName {
ListString namelist = new ArrayListString();
public void PrintMenu() {
System.out.println("\n\r1.Add new name " + "2.Display all name"
+ " 3.Quit"
+ "\nPlease select menu(1,2,3)");
}
public void displayname() {
for (int w = 0; wthis.namelist.size(); w++) {
System.out.println("Name" + w+":" + this.namelist.get(w));
}
}
public List addName(String name) {
namelist.add(name);
return namelist;
}
public static void main(String[] args) throws IOException {
ManageName a = new ManageName();
a.addName("jing5083394");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
while (true) {
a.PrintMenu();
String content = in.readLine();
if (content.equalsIgnoreCase("3")) {
break;
} else if (content.equalsIgnoreCase("1")) {
String name;
BufferedReader in2 = new BufferedReader(new InputStreamReader(
System.in));
System.out.println("Please input the Name to add new user");
String content2 = in.readLine();
name = content2;
a.addName(name);
System.out.println("Add name successfully\r\n");
}
else if (content.equalsIgnoreCase("2")) {
a.displayname();
}
else {
System.out.println("Invalid selections!\n");
}
}
}
}
//第二题: 把文件放到namefile.txt
/*
* 从namefile.txt文件中读入入门java要多少代码的字符串全部转换成大写字母入门java要多少代码,
* 再按原来的顺序输出到yoursData.txt文件中 。
*/
import java.lang.Character;
import java.io.*;
//将一个文件复制到另一个文件中(覆盖)
public class Filestream {
public static void main(String args[]) {
try {
File inFile = new File("c:\\namefile.txt");
File outFile = new File("c:\\yoursData.txt");
FileInputStream fis = new FileInputStream(inFile); // 读输入文件
FileOutputStream fos = new FileOutputStream(outFile);
int c;
while ((c = fis.read()) != -1) {
c = Character.toUpperCase(c);
fos.write(c);
}// 写入文件中
System.out.println("Output file finish");
fis.close();
fos.close();
} catch (FileNotFoundException e) {
System.out.println("FileStreamsTest: " + e);
} catch (IOException e) {
System.err.println("FileStreamsTest: " + e);

推荐阅读