大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
package testPackage;
创新互联凭借专业的设计团队扎实的技术支持、优质高效的服务意识和丰厚的资源优势,提供专业的网站策划、成都网站建设、网站制作、网站优化、软件开发、网站改版等服务,在成都10余年的网站建设设计经验,为成都上千多家中小型企业策划设计了网站。
import java.util.*;
public class 纤庆ikjkk {
public static void main(String[] args) {
Scanner saomiaoyi = new Scanner(System.in);
int he = 0;
for () {
System.out.println("请输入一共有多少丛汪笔交易:");
int shu = saomiaoyi.nextInt();
//Double[]shuzu={shu}; //这样是错的
Double[] shuzu = new Double[shu]; //要用new来动态定义数组
for (int i = 0; i shu; i++) {
System.out.println("开始输入第" + (i + 1) + "个数字");
shuzu[i] = saomiaoyi.nextDouble();
he += shuzu[i];
}
System.out.println("你一共录入了" + shu + "笔交易!");
System.out.print("所有交易的和为:"毁郑握 + he);
}
}
}
最简单的java代码此逗肯定就是这个了,如下:
public class MyFirstApp
{
public static void main(String[] args)
{
System.out.print("Hello world");
}
}
“hello world”就是应该是所有学java的新手看的第一个代码了。如果是零基础的新手朋友们可以来我们的java实验班试听,有免费的试听课程帮助学习java必备基础知识,有助教老师为零基础的人提差扒型供个人学习方案,学习完成后有考评团进行专业测试,帮助测评学员是否适合继续学习java,15天内免费帮助来报名体验实验班的虚猜新手快速入门java,更好的学习java!
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.awt.datatransfer.*;
class MyMenuBar extends MenuBar{
public MyMenuBar(Frame parent){
parent.setMenuBar(this);
}
public void addMenus(String [] menus){
for(int i=0;imenus.length;i++)
add(new Menu(menus[i]));
}
public void addMenuItems(int menuNumber,String[] items){
for(int i=0;iitems.length;i++){
if(items[i]!=null)
getMenu(menuNumber).add(new MenuItem(items[i]));
else getMenu(menuNumber).addSeparator();
}
}
public void addActionListener(ActionListener al){
for(int i=0;igetMenuCount();i++)
for(int j=0;j袭禅getMenu(i).getItemCount();j++)
getMenu(i).getItem(j).addActionListener(al);
}
}
class MyFile{
private FileDialog fDlg;
public MyFile(Frame parent){
fDlg=new FileDialog(parent,"",FileDialog.LOAD);
}
private String getPath(){
return fDlg.getDirectory()+"\\"+fDlg.getFile();
}
public String getData() throws IOException{
fDlg.setTitle("打开");
fDlg.setMode(FileDialog.LOAD);
fDlg.setVisible(true);
BufferedReader br=new BufferedReader(new FileReader(getPath()));
StringBuffer sb=new StringBuffer();
String aline;
while((aline=br.readLine())!=null)
sb.append(aline+'\n');
br.close();
return sb.toString();
}
public void setData(String data) throws IOException{
fDlg.setTitle("保拍察尘没春存");
fDlg.setMode(FileDialog.SAVE);
fDlg.setVisible(true);
BufferedWriter bw=new BufferedWriter(new FileWriter(getPath()));
bw.write(data);
bw.close();
}
}
class MyClipboard{
private Clipboard cb;
public MyClipboard(){
cb=Toolkit.getDefaultToolkit().getSystemClipboard();
}
public void setData(String data){
cb.setContents(new StringSelection(data),null);
}
public String getData(){
Transferable content=cb.getContents(null);
try{
return (String) content.getTransferData(DataFlavor.stringFlavor);
//DataFlavor.stringFlavor会将剪贴板中的字符串转换成Unicode码形式的String对象。
//DataFlavor类是与存储在剪贴板上的数据的形式有关的类。
}catch(Exception ue){}
return null;
}
}
class MyFindDialog extends Dialog implements ActionListener{
private Label lFind=new Label("查找字符串");
private Label lReplace=new Label("替换字符串");
private TextField tFind=new TextField(10);
private TextField tReplace=new TextField(10);
private Button bFind=new Button("查找");
private Button bReplace=new Button("替换");
private TextArea ta;
public MyFindDialog(Frame owner,TextArea ta){
super(owner,"查找",false);
this.ta=ta;
setLayout(null);
lFind.setBounds(10,30,80,20);
lReplace.setBounds(10,70,80,20);
tFind.setBounds(90,30,90,20);
tReplace.setBounds(90,70,90,20);
bFind.setBounds(190,30,80,20);
bReplace.setBounds(190,70,80,20);
add(lFind);
add(tFind);
add(bFind);
add(lReplace);
add(tReplace);
add(bReplace);
setResizable(false);
bFind.addActionListener(this);
bReplace.addActionListener(this);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
MyFindDialog.this.dispose();
}
});
}//构造函数结束
public void showFind(){
setTitle("查找");
setSize(280,60);
setVisible(true);
}
public void showReplace(){
setTitle("查找替换");
setSize(280,110);
setVisible(true);
}
private void find(){
String text=ta.getText();
String str=tFind.getText();
int end=text.length();
int len=str.length();
int start=ta.getSelectionEnd();
if(start==end) start=0;
for(;start=end-len;start++){
if(text.substring(start,start+len).equals(str)){
ta.setSelectionStart(start);
ta.setSelectionEnd(start+len);
return;
}
}
//若找不到待查字符串,则将光标置于末尾
ta.setSelectionStart(end);
ta.setSelectionEnd(end);
}
public Button getBFind() {
return bFind;
}
private void replace(){
String str=tReplace.getText();
if(ta.getSelectedText().equals(tFind.getText()))
ta.replaceRange(str,ta.getSelectionStart(),ta.getSelectionEnd());
else find();
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==bFind)
find();
else if(e.getSource()==bReplace)
replace();
}
}
public class MyMemo extends Frame implements ActionListener{
private TextArea editor=new TextArea(); //可编辑的TextArea
private MyFile mf=new MyFile(this);//MyFile对象
private MyClipboard cb=new MyClipboard();
private MyFindDialog findDlg=new MyFindDialog(this,editor);
public MyMemo(String title){ //构造函数
super(title);
MyMenuBar mb=new MyMenuBar(this);
//添加需要的菜单及菜单项
mb.addMenus(new String[]{"文件","编辑","查找","帮助"});
mb.addMenuItems(0,new String[]{"新建","打开","保存",null,"全选"});
mb.addMenuItems(1,new String[]{"剪贴","复制","粘贴","清除",null,"全选"});
mb.addMenuItems(2,new String[]{"查找",null,"查找替换"});
mb.addMenuItems(3,new String[]{"我的记事本信息"});
add(editor); //为菜单项注册动作时间监听器
mb.addActionListener(this);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
MyMemo.this.dispose();
}
}); //分号不能忘了
} //构造函数完
public void actionPerformed(ActionEvent e){
String selected=e.getActionCommand(); //获取菜单项标题
if(selected.equals("新建"))
editor.setText("");
else if(selected.equals("打开")){
try{
editor.setText(mf.getData());
}catch(IOException ie){}
}
else if(selected.equals("保存")){
try{
mf.setData(editor.getText());
}catch(IOException ie){}
}
else if(selected.equals("退出")){
dispose();
}
else if(selected.equals("剪贴")){
//将选中的字符串复制到剪贴板中并清除字符串
cb.setData(editor.getSelectedText());
editor.replaceRange("",editor.getSelectionStart(),editor.getSelectionEnd());
}
else if(selected.equals("复制")){
cb.setData(editor.getSelectedText());
}
else if(selected.equals("粘贴")){
String str=cb.getData();
editor.replaceRange(str,editor.getSelectionStart(),editor.getSelectionEnd());
//粘贴在光标位置
}
else if(selected.equals("清除")){
editor.replaceRange("",editor.getSelectionStart(),editor.getSelectionEnd());
}
else if(selected.equals("全选")){
editor.setSelectionStart(0);
editor.setSelectionEnd(editor.getText().length());
}
else if(selected.equals("查找")){
findDlg.showFind();
}
else if(selected.equals("查找替换")){
findDlg.showReplace();
}
}
public static void main(String[] args){
MyMemo memo=new MyMemo("记事本");
memo.setSize(650,450);
memo.setVisible(true);
}
}