本文目录一览:
求一段简单JAVA代码 非常简单
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
public class Group {
public static void main(String[] args) {
ListInteger l = new LinkedListInteger();
int[][] group = new int[4][7];
Random r = new Random();
for (int i = 0; i 31; i++)
l.add(new Integer(i + 1));
for (int i = 0; i 4; i++) {
for (int j = 0; j 7; j++) {
int k = r.nextInt(l.size());
group[i][j] = l.get(k);
l.remove(k);
}
}
for (int i = 0; i 4; i++) {
System.out.print("Group " + (i + 1) + ": ");
for (int j = 0; j 7; j++) {
System.out.print(group[i][j] + " ");
}
System.out.println();
}
// 剩下分组
String groups = "";
for(Integer _tem : l) {
groups += _tem + " ";
}
System.out.print("Group " + "5" + ": " + groups);
}
}
用java代码实现
package test;
import java.awt.FlowLayout;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class FrameDemo extends JFrame implements Runnable {
public void run() {
try{
while(true){
Date date=new Date();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月");
SimpleDateFormat sdf1=new SimpleDateFormat("dd");
SimpleDateFormat sdf2=new SimpleDateFormat("hh:mm:ss");
String week=getWeekOfDate(date);
GregorianCalendar ca = new GregorianCalendar();
String apm="";
int check=ca.get(GregorianCalendar.AM_PM);
if(check==0){
apm="上午";
}else if(check==1){
apm="下午";
}
JLabel jl = new JLabel("html"
+ "div align='center'"+sdf.format(date)+"/div"
+ "div align='center'font size=50"+sdf1.format(date)+"/font日/div"
+ "div align='center'"+week+"/div"
+ "div align='center'"+apm+sdf2.format(date)+"/div"
+ "/html");
add(jl);
setLayout(new FlowLayout());
setSize(150,150);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
Thread.sleep(1000);
//jl.setText(null);
remove(jl);
}
}catch(Exception e){}
}
public static String getWeekOfDate(Date dt) {
String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
Calendar cal = Calendar.getInstance();
cal.setTime(dt);
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (w 0)
w = 0;
return weekDays[w];
}
public static void main(String[] args) {
FrameDemo mr = new FrameDemo();
Thread t1 = new Thread(mr);
t1.start();
}
}
如何用Java代码实现
在servlet里面写就可以了
引入一系列包
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
public class Servlet1 extends HttpServlet {
public void doGet(ServletRequest req,ServletResponse res)throws ServletException, IOException{try{PrintWriter pw=res.getWriter();//在浏览器输出需要
pw.println("scriptscript");}catch(Exception e){
e.printStackTrace();//为发现调试错误}}}
试试吧,就是这样就可以了,把你要输出的HTML这些放在 pw.println("这里放HTML");就OK了
一个简单的Java程序代码?
package com.zpp;public class Charge {
public static void main(String [] args) {
if(args.length ==0) {
System.out.println("parameter error!");
System.out.println("java com.zpp.Charge [int]");
return;
}
int min = Integer.parseInt(args[0]);
double money = 0.0;
if (min = 0) {
money =0.0;
System.out.println("not money");
} else if (min = 60) {
money = 2.0;
} else {
money = 2.0 + (min - 60) * 0.01;
}
System.out.println("please pay: " + money);
}
} 编译:javac -d . Charge.java运行:java com.zpp.Charge 111
简单JAVA代码
输出错了!!!
第一个类的构造方法,请看
public tt(int b) {
b=x;
}
请问,你new出来tt这个类了,x有值了吧?
也就是说你在这里把x赋给了b,但是在第二个方法又无法用到b,也就是说,这个方法毫无用处
请将 b 和x的位置换换,同时,x为成员变量,不需要初始化给值的,是靠你传参数的。
第二,请看
public int cc(int b) {
b=x*2;
return b;
}
你可以完全把这个方法里的传参去掉,应为你的x是成员变量,改为
public int cc() {
return x*2;
}
然后在另外一个类里new出来tt,请看,我帮你修改了
Scanner a =new Scanner(System.in);
int b = a.nextInt();
tt cd =new tt(b);
int sd= cd.cc();
System.out.println(sb);
其实还可以改,
Scanner a =new Scanner(System.in);
tt cd =new tt(a.nextInt());
System.out.println(cd.cc());
给段最简单的java代码 让我新手看一下
最简单的java代码肯定就是这个了,如下:
public class MyFirstApp
{
public static void main(String[] args)
{
System.out.print("Hello world");
}
}
“hello world”就是应该是所有学java的新手看的第一个代码了。如果是零基础的新手朋友们可以来我们的java实验班试听,有免费的试听课程帮助学习java必备基础知识,有助教老师为零基础的人提供个人学习方案,学习完成后有考评团进行专业测试,帮助测评学员是否适合继续学习java,15天内免费帮助来报名体验实验班的新手快速入门java,更好的学习java!