java简单程序代码大全,Java简单代码

1,Java简单代码Iterator是对集合的一种遍历方式,next()方法的实现主要是有个内置的计数器 , 每调用一次next()方法将指向list的指针下移一位,int count=0;public Object next() Object result =list.get(count);count++;return result ; }这个是最最简单的!初学者的第一个程序代码!class demopublic static void main(string[] args)system.out.println("hello world!"); }}
2,给段最简单的java代码 让我新手看一下最简单的JAVA代码如下:interface a =========没有比这个更简单的了吧???给分吧小哥第一个for循环里面的int j=1;应该改为i=1;//文件名:HelloWorld.java public class HelloWorld public static void main(String args[]) //向屏幕上写字符串"HelloWorld!" System.out.println("HelloWorld!"); } }去BAIDU里搜搜有很多带注释的都很清楚在windows平台上显示一条信息. import Javax.swing.JOptionPane; //调用method public class HelloDialog public static void main(String[] args) JOptionPane.showMessageDialog( null, "Hello, this is a basic Java program! hope you like it" ); //显示一条信息 System.exit(0); // 结束程序 }//结束method }//结束class 这是一个java程序最基本的结构.希望大家喜欢. ============================================ 资料引用:http://www.knowsky.com/362434.htmlpublic class aapublic static void main(String [] args)int a=0;//定义一个计数器for(int i=1;i<=100;i++)a=a+i;//加总和}System.out.println(a);//打印出总和}}答案5050
3,急简单JAVA编程代码public class Testpublic static void main(String[] args)MyRectangle rec = new MyRectangle(3, 5);MyRectangle square = new MySquare(4);System.out.println(rec.toString()); System.out.println(square.toString()); }}class MyRectangle protected double width; protected double length;public MyRectangle(double length, double width) this.width = width; this.length = length; } public double getLength()return length; } public double getWidth()return width; } public void setWidth(double width)this.width = width; }public double getArea() return this.width * this.length; }public String toString() return "长方形的长为:" + length + ", 宽: " + width + ", 面积为:" + getArea(); }}class MySquare extends MyRectangle public MySquare(double length) super(length, length); }public double getArea() return Math.pow(super.width, 2); } public String toString() return "正方形边长为: " + super.length + ", 面积为: " + getArea(); }}----------测试长方形的长为:3.0, 宽: 5.0, 面积为:15.0正方形边长为: 4.0, 面积为: 16.0【java简单程序代码大全,Java简单代码】
4,求一个简单java程序代码谢谢public class TestStar public static void main(String[] args) String star = "*"; for (int i = 0; i < 5; i++) if (i == 0) System.out.print(" " + star); System.out.println(); } if (i == 1) for (int z = 0; z < 4; z++) System.out.print(" " + star); } System.out.println(); } if (i == 2) System.out.print(" "); for (int x = 0; x < 3; x++) System.out.print(" " + star); } System.out.println(); } if (i == 3) for (int y = 0; y < 2; y++) System.out.print(" " + star + " "); } } } } } 是好使的 但是我没找到画五角星有什么规律(五角星好象不是正规图形吧?)如果还有什么要求的话 补充问题(如果是用*填充所有的东西 不包括 “ ”的话 我可以重新再给你写一个)刚开始java的时候用记事本编写java源代码,在命令提示符中完成java程序的编译和运行过程,这样是为了更好的理解java基础 。以后可以用Eclipse或其他的开发环境 。eclipse有自己的编译器ECJ,会自动进行编译,编写、编译、运行等都可以在一个平台上完成 。这样就不用借助cmd手动编译Java程序了 。applacation 还是applet?import java.awt.Dimension;import java.awt.Graphics;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JPanel;public class Painter extends JFrame/****/private static final long serialVersionUID = 8160427604782702376L;CanvasPanel canvas = new CanvasPanel();;public Painter() super("Star");this.add(canvas);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.pack();this.setResizable(false);this.setLocationRelativeTo(null);this.setVisible(true);}public static void main(String[] args) new Painter();}}class CanvasPanel extends JPanel implements ActionListener/****/private static final long serialVersionUID = -4642528854538741028L;private JButton[] btn = new JButton[4];private String[] btn_name = private int center_x = 200, center_y = 200, radius = 100, degree = 0;public CanvasPanel() this.setPreferredSize(new Dimension(400, 500));this.setLayout(null);for(int i = 0; i < 4; i++) btn[i] = new JButton(btn_name[i]);btn[i].setBounds(160 + i * 60, 425, 50, 50);btn[i].addActionListener(this);this.add(btn[i]);}}@Overridepublic void paintComponent(Graphics g) super.paintComponent(g);for(int i = 0; i < 5; i++) g.drawLine( (int) (center_x + radius * Math.sin(Math.toRadians(degree + 72 * i))),(int) (center_y - radius * Math.cos(Math.toRadians(degree + 72 * i))),(int) (center_x + radius * Math.sin(Math.toRadians(degree + 72 * i + 144))),(int) (center_y - radius * Math.cos(Math.toRadians(degree + 72 * i + 144))));}}public void actionPerformed(ActionEvent e) // TODO Auto-generated method stubif(e.getActionCommand() == "+") if(radius < 200)radius += 2;repaint();} else if(e.getActionCommand() == "-") if(radius > 0)radius -= 2;repaint();} else if(e.getActionCommand() == "R") degree = (degree + 2) % 360;repaint();} else if(e.getActionCommand() == "L") degree = (degree - 2) % 360;repaint();}}}拓展资料Java是一种可以撰写跨平台应用程序的面向对象的程序设计语言 。Java 技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于PC、数据中心、游戏控制台、科学超级计算机、移动电话和互联网,同时拥有全球最大的开发者专业社群 。

    推荐阅读