一段完整的java代码 编写一段java代码
一段JAVA代码
Scanner
漳县网站制作公司哪家好,找创新互联建站!从网页设计、网站建设、微信开发、APP开发、成都响应式网站建设公司等网站项目制作,到程序开发,运营维护。创新互联建站成立与2013年到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联建站。
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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class TestString {
public static void main(String[] args) throws IOException {
boolean flag = false;
do {
System.out.println();
System.out.println("Do you want to continue?(Y/N)");
Scanner scan = new Scanner(System.in);
String banlance = scan.next();
if (banlance.equals("Y")) {
flag = true;
} else if(banlance.equals("N")) {
System.out.println("End!");
break;
} else {
System.out.println("Error Input!");
}
System.out.print("Please input the String: ");
BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));
String str = br.readLine();
StringBuffer strBuffer = new StringBuffer(str);
for(int i=0; istrBuffer.length(); i++) {//将元音字母先删掉
char c = strBuffer.charAt(i);
if ((c == 'a') || (c == 'e') || (c == 'i') || (c == 'o') || (c == 'u')) {
strBuffer = strBuffer.deleteCharAt(i);
--i;
}
}
for(int i=0,j=i+1; jstrBuffer.length(); i++,j++) {//处理重复辅音字母
char c1 = strBuffer.charAt(i), c2 = strBuffer.charAt(j);
if(c1 == c2) {
strBuffer = strBuffer.deleteCharAt(i);
--i;
--j;
}
}
System.out.println(strBuffer);
} while (flag = true);
}
}
测试与结果:
一段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代码 编写一段java代码
网页网址:http://azwzsj.com/article/hhesic.html