哪位高手帮写个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文件中读入的字符串全部转换成大写字母,
* 再按原来的顺序输出到yoursData.txt文件中 。
*/
import java.lang.Character;
【java基础小程序代码 java基础小程序代码有哪些】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);
}
}
}
求java经典小程序代码代码如下java基础小程序代码:
public class HelloWorld {
public static void main(String []args) {
int a = 3, b = 7 ;
System.out.println("Hello World!");
}
public static int f(int a, int b){
return a*aa*bb*b;
}
}
结果如下java基础小程序代码:
java小程序入门先到官网下载myeclipse或者eclipse编程软件,并配置java环境变量,在百度搜索栏依次搜索eclipse下载和搜索java环境变量的配置,就可以找到图文并茂的详细教程 。下面介绍一下怎么制作小程序:
1、打开myeclispe(eclipse都一样),依次点击File-New-Java Project,然后给这个项目起一个名字(随便起),这里就叫MyFirst.然后点击Finish;
2、在myeclipse左侧找到自己建好的MyFirst项目,左键点击 , 下面有文件件src,点击src,右键,依次点击New-Class,然后给这个新的类起一个名字(随便起),我这里叫MyFirstClass,然后点击Finish;
3、复制粘贴下面这些代码到MyFirstClass.java文件中,然后ctrl s , 保存;
4、在MyFirstClass.java文件的空白处右键选择 Run As --Java Application,你就会在下方的控制台看到hello worl 。
扩展资料:
Java是一门面向对象编程语言,不仅吸收了C语言的各种优点,还摒弃了C里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征 。Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程 。
参考资料:Java-百度百科
急求大神发几个java 300行代码的小程序 简单点的/**
* 文件名:Operation.java 2014-1-2 下午3:06:37
* @author Administrator
*/
package cc.icoc.javaxu.action;
import java.util.ArrayList;
import java.util.Scanner;
import cc.icoc.javaxu.datas.StudentInfo;
/**
* @author 许仕永
* 创建时间: 2014 2014-1-2 下午3:06:37
*/
public class Operation
{
int stuNo,stuAge;
String stuName,stuClass,stuSex;
ArrayListStudentInfo list;
/**程序入口
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
new Operation().operation();
}
private int inputInt()
{
Scanner scanner = new Scanner(System.in);
return scanner.nextInt();
}
private String inputStr()
{
Scanner scanner = new Scanner(System.in);
return scanner.nextLine();
}
private void operation()
{
// TODO Auto-generated method stub
if(list == null)
{
list = new ArrayListStudentInfo();
}
while(true)
{
System.out.println("\t\t\t学生信息管理系统\n");
System.out.println("1.信息查阅");
System.out.println("2.信息查询");
System.out.println("3.信息录入");
System.out.println("4.退出系统");
int what = inputInt();
if ( what == 1 )
{
getInfo();
} else if ( what == 2 )
{
allSerach();
} else if ( what == 3 )
{
inputInfo();
} else if( what == 4 )
{
System.out.println("已经退出系统");
System.exit(0);
}
}
}
/**
* 获取全部学生的信息列表
*/
private void getInfo()
{
if(!list.isEmpty())
{
for ( int i = 0; ilist.size(); i)
{
System.out.println(list.get(i));
}
}
}
/**
* 执行查找
*/
private void allSerach()
{
System.out.println("1.输入学号进行查询");
System.out.println("2.输入姓名进行查询");
int what = inputInt();
if(what == 1)
{
System.out.println("请输入学号:");
search(inputInt());
}
else
{
System.out.println("请输入姓名:");
search(inputStr());
}
}
/**
* 按学生姓名查询学生信息
* @param name学生姓名
*/
private StudentInfo search(String name)
{
for ( int i = 0; ilist.size(); i)
{
if(list.get(i).getStuName().equals(name))
{
System.out.println(list.get(i));
return list.get(i);
}
}
System.out.println("未查询到该名字的学生");
return null;
}
/**
* 按学号查询学生信息
* @param id 学号
*/
private StudentInfo search(int id)
{
for ( int i = 0; ilist.size(); i)
{
if(list.get(i).getStuNo()==id)
{
System.out.println(list.get(i));
return list.get(i);
}
}
System.out.println("未查询到该学号的学生");
return null;
}
/**
* 录入学生信息
*/
private void inputInfo()
{
try
{
System.out.print("请输入学生学号:\n");
stuNo = inputInt();
System.out.print("请输入学生姓名:\n");
stuName = inputStr();
System.out.print("请输入学生性别:\n");
stuSex = inputStr();
System.out.print("请输入学生年龄:\n");
stuAge = inputInt();
System.out.print("请输入学生班级:\n");
stuClass = inputStr();
list.add(new StudentInfo(stuNo, stuAge, stuName, stuSex, stuClass));
} catch (Exception e)
{
// TODO: handle exception
System.out.println("不允许为空,请重新输入");
}
}
}
package cc.icoc.javaxu.action;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Stu
{
int countStu = 0;
int sum = 0;
int avg = 0;
ListStuBean list = new ArrayListStu.StuBean();
public static void main(String[] args)
{
new Stu().go();
}
private void go()
{
A:while(true)
{
//构造实体Bean来存储学生成绩
StuBean bean = new StuBean();
System.out.println("请输入成绩:");
System.out.println("语文:");
bean.setYuwen(scanner());
System.out.println("数学:");
bean.setMath(scanner());
//获取英语成绩
System.out.println("英语:");
bean.setEnglish(scanner());
//存入容器
list.add(bean);
for ( int i = 0; ilist.size(); i)
{
sum= list.get(i).english list.get(i).math list.get(i).yuwen;
}
avg = sum / (3*list.size());
System.out.println("当前有" list.size() "条学生记录,所有学生总分=" sum "平均分为" avg);
//输入y继续录入学生信息,输入x退出
System.out.println("\n已成功录入一个学生的数据,是否继续/退出(y/x)");
if("x".equals(scannerString()))
break A;
}
}
/**输入*/
private int scanner()
{
Scanner scanner = new Scanner(System.in);
return scanner.nextInt();
}
/**输入*/
private String scannerString()
{
Scanner scanner = new Scanner(System.in);
return scanner.nextLine();
}
class StuBean
{
int math;
int yuwen;
int english;
public int getMath()
{
return math;
}
public void setMath(int math)
{
this.math = math;
}
public int getYuwen()
{
return yuwen;
}
public void setYuwen(int yuwen)
{
this.yuwen = yuwen;
}
public int getEnglish()
{
return english;
}
public void setEnglish(int english)
{
this.english = english;
}
}
}
/**
* 文件名:StudentInfo.java 2014-1-2 下午3:07:29
* @author Administrator
*/
package cc.icoc.javaxu.datas;
/**
* @author 许仕永
* 创建时间: 2014 2014-1-2 下午3:07:29
*/
public class StudentInfo
{
int stuNo,stuAge;
String stuName,stuSex,stuClass;
public StudentInfo(int stuNo, int stuAge, String stuName, String stuSex, String stuClass)
{
super();
this.stuNo = stuNo;
this.stuAge = stuAge;
this.stuName = stuName;
this.stuSex = stuSex;
this.stuClass = stuClass;
}
public int getStuNo()
{
return stuNo;
}
public void setStuNo(int stuNo)
{
this.stuNo = stuNo;
}
public int getStuAge()
{
return stuAge;
}
public void setStuAge(int stuAge)
{
this.stuAge = stuAge;
}
public String getStuName()
{
return stuName;
}
public void setStuName(String stuName)
{
this.stuName = stuName;
}
public String getStuSex()
{
return stuSex;
}
public void setStuSex(String stuSex)
{
this.stuSex = stuSex;
}
public String getStuClass()
{
return stuClass;
}
public void setStuClass(String stuClass)
{
this.stuClass = stuClass;
}
@Override
public String toString()
{
// TODO Auto-generated method stub
String s = "学号:" getStuNo() "\t姓名:" getStuName() " \t性别:" getStuSex() "\t年龄:" getStuAge() "\t班级:" getStuClass();
return s;
}
}
谁能给个JAVA的小程序代码 , 越小越好!这是java基础小程序代码我晓得的最简单的java小程序代码java基础小程序代码了java基础小程序代码你可以看看:
package com.kenki.emp;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.SQLException;
import java.sql.*;
public class emp extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
String code = request.getParameter("code");
String name = request.getParameter("name");
String pay = request.getParameter("pay");
System.out.println("empcode:"code);
System.out.println("name:"name);
System.out.println("pay:"pay);
//创建驱动
new com.microsoft.jdbc.sqlserver.SQLServerDriver();
String strd =
"jdbc:microsoft:sqlserver://localhost:1433;databasename=emp_dates";
String username = "sa";
String pws = "";
try {
java.sql.Connection conn = java.sql.DriverManager.getConnection(
strd, username, pws);
String strs = "insert into emp values(?,?,?)";
java.sql.PreparedStatement pre = conn.prepareStatement(strs);
pre.setString(1, code);
pre.setString(2, name);
pre.setString(3, pay);
pre.execute();
pre.close();
conn.close();
//重定向至查询页面
out.println("成功保存java基础小程序代码!java基础小程序代码!");
response.sendRedirect("emp.html");
} catch (SQLException ss) {
ss.printStackTrace();
response.sendRedirect("/WebModule1/error.html");
}
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}
//Clean up resources
public void destroy() {
}
}
关于java基础小程序代码和java基础小程序代码有哪些的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。
推荐阅读
- 没有手机怎么测试硬盘大小,如何检测手机硬盘
- 为什么cpu还分雕和雷,cpu是雷是雕
- 安卓自带高清播放器下载,安卓自带的播放器
- JAVA多线程求素数代码 java多线程计数并输出
- 安卓能录音的手机软件,安卓手机录音app推荐
- sublime自动识别html代码格式,sublime怎么自动生成html
- u盘有什么牌子,u盘什么牌子好
- php大数据平台搭建 php 大数据框架
- u盘视频为什么放不出来,u盘里面的视频怎么放不了