最简单的java代码肯定就是这个了,如下:
成都创新互联公司主要从事网页设计、PC网站建设(电脑版网站建设)、wap网站建设(手机版网站建设)、响应式网站建设、程序开发、网站优化、微网站、小程序设计等,凭借多年来在互联网的打拼,我们在互联网网站建设行业积累了丰富的网站设计、网站制作、网站设计、网络营销经验,集策划、开发、设计、营销、管理等多方位专业化运作于一体。
public class MyFirstApp
{
public static void main(String[] args)
{
System.out.print("Hello world");
}
}
“hello world”就是应该是所有学java的新手看的第一个代码了。如果是零基础的新手朋友们可以来我们的java实验班试听,有免费的试听课程帮助学习java必备基础知识,有助教老师为零基础的人提供个人学习方案,学习完成后有考评团进行专业测试,帮助测评学员是否适合继续学习java,15天内免费帮助来报名体验实验班的新手快速入门java,更好的学习java!
代码如下:
for (int a = 1; a=100; a++)
{
system.out.println(a);
}
/////////
int a =1;
while (a =100)
{
system.out.println(a);
a++;
}
/////////
int a = 1;
do
{
system.out.println(a);
a++;
}
while (a=100)
扩展资料:
在windows下编译java文件、执行:
1、先创建一个txt,更改为test.java。
2、编写代码,为输出为holloword。
3、找到cmd,并进行打开cmd。
4、编译java文件,输入命令为javac test.java。
5、如果没有报错,查看当前目录下是否有class文件产生。
6、执行class文件,在命令输入java test,输出为holloword。
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 = {"+", "-", "R", "L"};
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]);
}
}
@Override
public 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 stub
if(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();
}
}
}
给你一个前几天才帮人写的
“计算整钱兑零”。程序要求用户输入一个双精度数代表总元数,就会列出总值与其等价的1元币、二角五分币、5分币和1分币的数目。程序报告的数目是1元币的最大数、其次是二角五分币的最大数,等等,依此类推。只显示非零的单位。对单个单位显示单数单词,对多于一个单位的显示复数单词
import java.util.Scanner;
public class MoneyCalculate {
public static void main(String[] args) {
int max100 = 0;
int max25 = 0;
int max5 = 0;
int max1 = 0;
double money = getMoneyFromInput();
String str = String.valueOf(money).trim();
String[] ary = str.split("\\.");
max100 = Integer.parseInt(ary[0]);
if(ary.length == 2){
int fen = Integer.parseInt(ary[1]);
if(ary[1].trim().length() == 1){
fen = Integer.parseInt(ary[1]) * 10;
}
max25 = fen / 25;
if(fen % 25 != 0){
fen = fen % 25;
}else{
fen = 0;
}
max5 = fen / 5;
max1 = fen % 5;
}
StringBuilder sb = new StringBuilder(money + " = ");
if(max100 != 0){
sb.append(max100);
sb.append("*1 ");
}
if(max25 != 0){
sb.append(max25);
sb.append("*0.25 ");
}
if(max5 != 0){
sb.append(max5);
sb.append("*0.05 ");
}
if(max1 != 0){
sb.append(max1);
sb.append("*0.01 ");
}
System.out.println(sb.toString());
}
private static double getMoneyFromInput() {
Scanner scanner = new Scanner(System.in);
return scanner.nextDouble();
}
}
-----------
2.49
2.49 = 2*1 1*0.25 4*0.05 4*0.01
-----------
2.5
2.5 = 2*1 2*0.25
-----------
37.23
37.23 = 37*1 4*0.05 3*0.01
-----------------
123.569
123.569 = 123*1 22*0.25 3*0.05 4*0.01