网站建设资讯

NEWS

网站建设资讯

java代码段 什么是代码段

一段JAVA代码

Scanner

在怀柔等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供做网站、成都网站建设 网站设计制作按需求定制开发,公司网站建设,企业网站建设,成都品牌网站建设,成都全网营销推广,成都外贸网站建设,怀柔网站建设费用合理。

sc

=

new

Scanner(System.in);

System.out.print("请输入姓名:");

String

name

=

sc.nextLine();

System.out.print("请输入年龄:");

int

age

=

sc.nextInt();

System.out.print("请输入工资:");

float

salary

=

sc.nextFloat();

sc.nextLine();

////加多一行,读取输入工资是的\n换行符

System.out.print("请输入联系地址:");

String

addr

=

sc.nextLine();

System.out.print("请输入联系电话:");

String

pnumber

=

sc.nextLine();

System.out.println("你的信息如下:");

System.out.println("姓名:"

+

name);

System.out.println("年龄:"

+

age);

System.out.println("工资:"

+

salary);

System.out.println("联系地址:"

+

addr);

System.out.println("联系电话:"

+

pnumber);

如何用java写这段代码?

import java.security.InvalidKeyException;import java.security.NoSuchAlgorithmException;import javax.crypto.BadPaddingException;import javax.crypto.Cipher;import javax.crypto.IllegalBlockSizeException;import javax.crypto.KeyGenerator;import javax.crypto.NoSuchPaddingException;import javax.crypto.SecretKey;public class JEncrytion{

public static void main(String[] argv) {

try{ KeyGenerator keygenerator = KeyGenerator.getInstance("DES"); SecretKey myDesKey = keygenerator.generateKey();

Cipher desCipher; // Create the cipher

desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding");

// Initialize the cipher for encryption

desCipher.init(Cipher.ENCRYPT_MODE, myDesKey); //sensitive information

byte[] text = "No body can see me".getBytes();

System.out.println("Text [Byte Format] : " + text);

System.out.println("Text : " + new String(text));

// Encrypt the text

byte[] textEncrypted = desCipher.doFinal(text);

System.out.println("Text Encryted : " + textEncrypted);

// Initialize the same cipher for decryption

desCipher.init(Cipher.DECRYPT_MODE, myDesKey); // Decrypt the text

byte[] textDecrypted = desCipher.doFinal(textEncrypted);

System.out.println("Text Decryted : " + new String(textDecrypted));

}catch(NoSuchAlgorithmException e){

e.printStackTrace();

}catch(NoSuchPaddingException e){

e.printStackTrace();

}catch(InvalidKeyException e){

e.printStackTrace();

}catch(IllegalBlockSizeException e){

e.printStackTrace();

}catch(BadPaddingException e){

e.printStackTrace();

}

}

}

如何用Java代码段生成四位数字加字母的验证码?

不知道你问的是不是生成这种图片验证码?如果只要一个随机四位数 那这行代码就够了(new Random().nextInt(9000) + 1000;),如果是生成页面图片验证码就是下面的了: //设定 响应模式 resp.setContentType("image/jpeg"); // 生成令牌环数据; Integer token = new Random().nextInt(9000) + 1000; // 保存令牌环数据到session中 req.getSession().setAttribute(IMAGE_TOKEN_NAME, token); // 生成令牌环图片 ServletOutputStream out = resp.getOutputStream(); BufferedImage img = new BufferedImage(60, 20, BufferedImage.TYPE_INT_RGB); Graphics g = img.getGraphics(); g.setColor(Color.YELLOW); g.fillRect(0, 0, img.getWidth(), img.getHeight()); g.setColor(Color.BLUE); g.setFont(new Font("", Font.BOLD, 18)); g.drawString(String.valueOf(token), 10, 16); ImageIO.write(img, "jpg", out); out.close();

下面简单的介绍他们的功能和用途,执行效率等。每个都有各自的优缺点看你是做甚什么方面的研究开发用。.net,是网站编程,现在很多都用这个,但是这个语言编程都有统一思路,很好掌握。窒息那个效率不是很高;php 支持跨平台,很容易学会,执行的效率很高;asp是ASP.net的前身,它比较稳定,比.net要弱一点。但是比.net好学。jsp 是网页编程,这个学习大约一周就能搞定,不过这个得多实践,不然的话,时间长了,就容易忘记。

我自己做的系统里面用作验证码的JSP的%@page contentType="image/jpeg;charset=utf-8"%%@page import="java.util.*,java.awt.*,java.awt.image.*,javax.imageio.*" %%@ page import="java.io.OutputStream" %html body %! Color getRandColor(int fc,int bc) { Random rd=new Random(); if(fc255) fc=255; if(bc255) bc=255; int red=fc+rd.nextInt(bc-fc); int green=fc+rd.nextInt(bc-fc); int blue=fc+rd.nextInt(bc-fc); return new Color(red,green,blue); } % % Random r=new Random(); response.addHeader("Pragma","No-cache"); response.addHeader("Cache-Control","no-cache"); response.addDateHeader("expires",0); int width=90; int height=23; BufferedImage pic=new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB); Graphics gc=pic.getGraphics(); gc.setColor(getRandColor(200,250)); gc.fillRect(0,0,width,height); String[] rNum ={"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f", "g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w", "x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N", "O","P","Q","R","S","T","U","V","W","X","Y","Z"}; int[] style = {Font.PLAIN,Font.BOLD,Font.ITALIC,Font.PLAIN+Font.BOLD, Font.BOLD+Font.ITALIC,Font.PLAIN+Font.ITALIC,Font.PLAIN+Font.BOLD+Font.ITALIC}; gc.setColor(Color.WHITE); gc.drawLine(0,30,90,10); gc.setColor(getRandColor(160,200)); for (int i=0;i50;i++) { int x = r.nextInt(width); int y = r.nextInt(height); int xl = r.nextInt(10); int yl = r.nextInt(10); gc.drawLine(x,y,x+xl,y+yl); } gc.setColor(getRandColor(60,150)); String rt = ""; for(int i=0;i4;i++){ String temp = rNum[r.nextInt(62)]; rt = rt+temp; gc.setFont(new Font("Times New Roman",style[r.nextInt(7)],15)); gc.drawString(temp,5+i*15+r.nextInt(10),10+r.nextInt(10)); } gc.dispose(); session.setAttribute("randNum",rt); OutputStream os=response.getOutputStream(); ImageIO.write(pic,"JPEG",os); System.out.println("当前验证码为:"+session.getAttribute("randNum")); os.flush(); os.close(); os=null; response.flushBuffer(); out.clear(); out = pageContext.pushBody(); % /body/html

一段java代码,可运行出来,至少50行代码,最好可以注释一下

就把打字游戏的给你吧

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import java.util.Random;

class WordPanel extends JPanel implements Runnable{

private Thread thread = null;

private int level = 1;

private Font font = new Font("宋体",Font.ITALIC+Font.BOLD,24);

private Color color = Color.BLUE;

public static final int x = 10;

private int y = 0;

private char word;//下落的字母

private static Random rand = new Random();

public void setY(int y){

this.y = y;

}

public void setWord(char word){

this.word = word;

}

public char getWord(){

return this.word;

}

public static char newChar(){

return (char)(97+rand.nextInt(26));

}

public WordPanel(){

word = newChar();

thread = new Thread(this);

thread.start();

}

public void paintComponent(Graphics g) {

super.paintComponent(g);

g.setFont(font);

g.setColor(color);

g.drawString(String.valueOf(word),x,y);

}

public void run(){

while (true){

try {

Thread.sleep(1000);

this.repaint();

if (y=this.getHeight()){

y = 0;

word = this.newChar();

}else

y+=20;

}

catch (Exception ex) {

ex.printStackTrace();

}

}

}

}

public class WordGame extends JFrame{

private WordPanel[] words = new WordPanel[10];

class Listener extends KeyAdapter{

public void keyTyped(KeyEvent e) {

char input = e.getKeyChar();

for (int i = 0; iwords.length; i++){

if ( input==words[i].getWord() ){

words[i].setWord(WordPanel.newChar());

words[i].setY(0);

words[i].repaint();

break;

}

}

}

}

public WordGame(String title){

super(title);//思考

Container c = this.getContentPane();

c.setLayout(new GridLayout(1,words.length));

this.addKeyListener( new Listener() );

for (int i = 0; iwords.length; i++){

words[i] = new WordPanel();

c.add(words[i]);

}

this.setSize( new Dimension(400,400) );

this.setVisible(true);

}

public static void main(String[] args){

WordGame game = new WordGame("简单的打字游戏");

}

}

java写一段代码

代码演示:有什么地方看不懂再问

public class Demo1 {

public static void main(String[] args) {

String str = "我们是一家人";

char[] ch = str.toCharArray();

char[] ch1 = new char[ch.length];

for (int i = 0; i ch.length; i++) {

ch1[i]=ch[ch.length-i-1];

}

String str1 = String.valueOf(ch1);

System.out.println(str1);

}

}

java中,什么是扩展段,代码段,数据段

应该都是指内存块....至于如何分配.看java

第一个 不懂了.有这东西么.???

二.... : 应该是在某个方法定义了一大堆 变量.比如 String ss = new String();Object obj = new Object();....  这样的一堆东西,在程序没跑到这个方法前 就已经规定好一个内存块 给这些个东西存了.

第三个  通俗点就是 我们在程序中定义的 Static 变量.或者 在程序跑起来时 在xml配置好的字典表的java所分配的内存块

, 比如 xml配置好一个map 1=男 2=女  存在数据库中的字段是1.要在页面上显示  map.get(1) 就是显示男了. 而这个map不需要每次去查询出来.

个人愚见!!!


本文名称:java代码段 什么是代码段
文章来源:http://cdweb.net/article/dooejig.html