JAVA程序查错

JAVA程序查错,第1张

你的程序我帮你改了一下,运行没问题了,你看看吧。键州

import java.awt.BorderLayout

import java.awt.Container

import java.awt.FlowLayout

import java.awt.GridLayout

import java.awt.event.WindowAdapter

import java.text.SimpleDateFormat

import java.util.Date

import java.util.Locale

import java.util.Timer

import java.util.TimerTask

import javax.swing.BorderFactory

import javax.swing.JButton

import javax.swing.JFrame

import javax.swing.JLabel

import javax.swing.JPanel

class EntryManagement extends WindowAdapter

{

JButton pb,st//声明需要调用的对象

JFrame f4

public JPanel showTime

private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss EEEEEEEEEE",Locale.ENGLISH)

JLabel timelabel=new JLabel()

private EntryManagement()//账散掘户管理系统冲亮核登陆界面

{

JFrame f4 = new JFrame()

Container contentPane = f4.getContentPane()

contentPane.setLayout(new BorderLayout())

showTime = new JPanel()

JLabel showType = new JLabel("Staff Only",JLabel.CENTER)

JPanel chooseType = new JPanel()

JPanel screen = new JPanel()

pb = new JButton("Public")

st = new JButton("Staff")

Timer timer = new Timer()

timer.schedule(new TimerTask(){

public void run() {

Date nowDate=new Date()

timelabel.setText(sdf.format(nowDate))

}

}, new Date(), 1000)

showTime.add(timelabel)

chooseType.setLayout(new FlowLayout())//把组件放到JPanel里并设置格式

chooseType.add(pb)

chooseType.add(st)

chooseType.setBorder(BorderFactory.createTitledBorder("Please Choose Your Identity"))

showType.setFont(new java.awt.Font("Dialog",1, 30))

screen.setLayout(new GridLayout(2,1))

screen.add(showTime)

screen.add(showType)

f4.add(chooseType,BorderLayout.SOUTH)//把JPanel放到主窗口里并设置格式

f4.add(screen,BorderLayout.CENTER)

f4.setTitle("Entry Management")

f4.setSize(400,300)

f4.setLocationRelativeTo(null)

f4.setVisible(true)

f4.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)

}

public static void main(String[] args)

{

EntryManagement a=new EntryManagement()

}

}

你的程序我看了一下,主要改了三个地方:

一、for(int ch=0ch<line.length()ch++)最后和升不应该有引号,改为去掉引号。

二、在for(int ch=0ch<line.length()ch++)循环后面加一句current=line.charAt(ch)

三、因为加了一纤州条语句所以在for(int ch=0ch<line.length()ch++)循环后加{}括起if 语句。

import java.util.Scanner

public class ex2 {

public static void main(String[] args) {

final int NUMCHARS=26

Scanner scan = new Scanner(System.in)

int[]upper=new int[NUMCHARS]

int[]low=new int[NUMCHARS]

char current=0

int other=0

System.out.println("enter a sentence:")

String line=scan.nextLine()

int ch

for( ch=0ch<line.length()ch++){

current=line.charAt(ch)

if (current>唤竖老='A' &&current<='Z')

upper[current-'A']++

else

if(current>='a' &&current<='z')

low[current-'a']++

else

other++

}

for(int i=0i<low.lengthi++)

System.out.println("a1["+i+"]="+low[i])

}

static void prt(String s){

System.out.println(s)}

}

运行结果:

enter a sentence:

asfwqw

a1[0]=1

a1[1]=0

a1[2]=0

a1[3]=0

a1[4]=0

a1[5]=1

a1[6]=0

a1[7]=0

a1[8]=0

a1[9]=0

a1[10]=0

a1[11]=0

a1[12]=0

a1[13]=0

a1[14]=0

a1[15]=0

a1[16]=1

a1[17]=0

a1[18]=1

a1[19]=0

a1[20]=0

a1[21]=0

a1[22]=2

a1[23]=0

a1[24]=0

a1[25]=0


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/12227069.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-22
下一篇2023-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存