Scanner
漳縣網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)建站!從網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)公司等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營維護(hù)。創(chuàng)新互聯(lián)建站成立與2013年到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)建站。
sc
=
new
Scanner(System.in);
System.out.print("請(qǐng)輸入姓名:");
String
name
=
sc.nextLine();
System.out.print("請(qǐng)輸入年齡:");
int
age
=
sc.nextInt();
System.out.print("請(qǐng)輸入工資:");
float
salary
=
sc.nextFloat();
sc.nextLine();
////加多一行,讀取輸入工資是的\n換行符
System.out.print("請(qǐng)輸入聯(lián)系地址:");
String
addr
=
sc.nextLine();
System.out.print("請(qǐng)輸入聯(lián)系電話:");
String
pnumber
=
sc.nextLine();
System.out.println("你的信息如下:");
System.out.println("姓名:"
+
name);
System.out.println("年齡:"
+
age);
System.out.println("工資:"
+
salary);
System.out.println("聯(lián)系地址:"
+
addr);
System.out.println("聯(lián)系電話:"
+
pnumber);
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++)?{//處理重復(fù)輔音字母
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);
}
}
測試與結(jié)果:
就把打字游戲的給你吧
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("簡單的打字游戲");
}
}
網(wǎng)站題目:一段完整的java代碼 編寫一段java代碼
標(biāo)題URL:http://sd-ha.com/article2/hhesic.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、品牌網(wǎng)站制作、小程序開發(fā)、服務(wù)器托管、做網(wǎng)站、網(wǎng)站內(nèi)鏈
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)