package com.zpp;public class Charge {
創(chuàng)新互聯(lián)建站是一家網(wǎng)站設(shè)計(jì)公司,集創(chuàng)意、互聯(lián)網(wǎng)應(yīng)用、軟件技術(shù)為一體的創(chuàng)意網(wǎng)站建設(shè)服務(wù)商,主營(yíng)產(chǎn)品:響應(yīng)式網(wǎng)站、品牌網(wǎng)站制作、成都全網(wǎng)營(yíng)銷。我們專注企業(yè)品牌在網(wǎng)站中的整體樹立,網(wǎng)絡(luò)互動(dòng)的體驗(yàn),以及在手機(jī)等移動(dòng)端的優(yōu)質(zhì)呈現(xiàn)。成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、移動(dòng)互聯(lián)產(chǎn)品、網(wǎng)絡(luò)運(yùn)營(yíng)、VI設(shè)計(jì)、云產(chǎn)品.運(yùn)維為核心業(yè)務(wù)。為用戶提供一站式解決方案,我們深知市場(chǎng)的競(jìng)爭(zhēng)激烈,認(rèn)真對(duì)待每位客戶,為客戶提供賞析悅目的作品,網(wǎng)站的價(jià)值服務(wù)。
public static void main(String [] args) {
if(args.length ==0) {
System.out.println("parameter error!");
System.out.println("java com.zpp.Charge [int]");
return;
}
int min = Integer.parseInt(args[0]);
double money = 0.0;
if (min = 0) {
money =0.0;
System.out.println("not money");
} else if (min = 60) {
money = 2.0;
} else {
money = 2.0 + (min - 60) * 0.01;
}
System.out.println("please pay: " + money);
}
} 編譯:javac -d . Charge.java運(yùn)行:java com.zpp.Charge 111
package tmp;
import java.awt.BorderLayout;
public class ShowIcon extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
ShowIcon frame = new ShowIcon();
frame.setVisible(true);
}
/**
* Create the frame.
*/
public ShowIcon() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
JLabel lbl = new JLabel("New label");
contentPane.add(lbl, BorderLayout.CENTER);
ImageIcon icon=new ImageIcon(getClass().getResource("/abc.jpg"));
lbl.setIcon(icon);
}
}
//圖片abc.jpg放到源代碼文件下 一般為src
不知道是否理解對(duì)了你的意思,大概寫了一下:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.io.StringWriter;
public class FileReadAndWrite {
private static final int DEFAULT_BUFFER_SIZE = 1024;
public static void main(String[] args) {
File file = new File("E:/workspace/FileIOTest/src/a.txt");
String str = file2String(file, "UTF-8");
str = str.replace('d', 'f');
string2File(str,"E:/workspace/FileIOTest/src/b.txt");
System.out.println("處理完畢");
}
/**
* 文本文件轉(zhuǎn)換為指定編碼的字符串
*
* @param file
* 文本文件
* @param encoding
* 編碼類型
* @return 轉(zhuǎn)換后的字符串
* @throws IOException
*/
public static String file2String(File file, String encoding) {
InputStreamReader reader = null;
StringWriter writer = new StringWriter();
try {
if (encoding == null || "".equals(encoding.trim())) {
reader = new InputStreamReader(new FileInputStream(file),
encoding);
} else {
reader = new InputStreamReader(new FileInputStream(file));
}
// 將輸入流寫入輸出流
char[] buffer = new char[DEFAULT_BUFFER_SIZE];
int n = 0;
while (-1 != (n = reader.read(buffer))) {
writer.write(buffer, 0, n);
}
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
if (reader != null)
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
// 返回轉(zhuǎn)換結(jié)果
if (writer != null)
return writer.toString();
else
return null;
}
/**
* 將字符串寫入指定文件(當(dāng)指定的父路徑中文件夾不存在時(shí),會(huì)最大限度去創(chuàng)建,以保證保存成功!)
*
* @param res
* 原字符串
* @param filePath
* 文件路徑
* @return 成功標(biāo)記
*/
public static boolean string2File(String res, String filePath) {
boolean flag = true;
BufferedReader bufferedReader = null;
BufferedWriter bufferedWriter = null;
try {
File distFile = new File(filePath);
if (!distFile.getParentFile().exists())
distFile.getParentFile().mkdirs();
bufferedReader = new BufferedReader(new StringReader(res));
bufferedWriter = new BufferedWriter(new FileWriter(distFile));
char buf[] = new char[1024]; // 字符緩沖區(qū)
int len;
while ((len = bufferedReader.read(buf)) != -1) {
bufferedWriter.write(buf, 0, len);
}
bufferedWriter.flush();
bufferedReader.close();
bufferedWriter.close();
} catch (IOException e) {
e.printStackTrace();
flag = false;
return flag;
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return flag;
}
}
package test;
public class Student {
private String name;
private String id;
private String clazz;
private int age;
private String address;
/**
* sayHello方法
*/
public void sayHello() {
System.out.println("學(xué)號(hào)為" + this.id + "的同學(xué)的具體信息如下:");
System.out.println("姓名:" + this.name);
System.out.println("班級(jí):" + this.clazz);
System.out.println("年齡:" + this.age);
System.out.println("家庭住址:" + this.address);
}
/**
* 測(cè)試方法
*
* @param args
*/
public static void main(String[] args) {
// 第一問
Student student = new Student();
student.setAddress("百度知道");
student.setAge(1);
student.setClazz("一班");
student.setId("071251000");
student.setName("lsy605604013");
student.sayHello();
// 第二問
Student studentNew = new Student();
studentNew.setAddress("搜搜知道");
studentNew.setAge(2);
studentNew.setClazz("二班");
studentNew.setId("071251001");
studentNew.setName("lady");
if (student.getAge() studentNew.getAge())
studentNew.sayHello();
else if (student.getAge() studentNew.getAge())
student.sayHello();
else
System.out.println("兩人一樣大");
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getClazz() {
return clazz;
}
public void setClazz(String clazz) {
this.clazz = clazz;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
最簡(jiǎn)單的java代碼肯定就是這個(gè)了,如下:
public class MyFirstApp
{
public static void main(String[] args)
{
System.out.print("Hello world");
}
}
“hello world”就是應(yīng)該是所有學(xué)java的新手看的第一個(gè)代碼了。如果是零基礎(chǔ)的新手朋友們可以來我們的java實(shí)驗(yàn)班試聽,有免費(fèi)的試聽課程幫助學(xué)習(xí)java必備基礎(chǔ)知識(shí),有助教老師為零基礎(chǔ)的人提供個(gè)人學(xué)習(xí)方案,學(xué)習(xí)完成后有考評(píng)團(tuán)進(jìn)行專業(yè)測(cè)試,幫助測(cè)評(píng)學(xué)員是否適合繼續(xù)學(xué)習(xí)java,15天內(nèi)免費(fèi)幫助來報(bào)名體驗(yàn)實(shí)驗(yàn)班的新手快速入門java,更好的學(xué)習(xí)java!
我是Java初學(xué)者,我看了你的問題后想了很久終于把它做出來了,你看看吧,方法不是很好,但能滿足你的要求:
import java.util.Scanner;
public class Check2{
int t;
char[] chs = new char[500]; //輸入的句子不能超過500個(gè)字符
Check2() {
String str;
Scanner sc = new Scanner(System.in);
System.out.println("請(qǐng)輸入字符串(輸入的字符串不能超過500個(gè)字符):");
str = sc.nextLine();
t=str.length();
for (int i = 0; i t; i ++) {
chs[i] = str.charAt(i); //將輸入的字符串裝入數(shù)組
}
}
}
class FuZhi{
char[] letter=new char[52]; //將52個(gè)字母(含大小寫)裝入數(shù)組
FuZhi(){
char p;
int i=0,j=26;
for(p='A';p='Z';p++){
letter[i]=p; //這句剛才寫掉了,加上去后程序就完整了
i++; //將A-Z裝入數(shù)組
}
for(p='a';p='z';p++){
letter[j]=p; //將a-z裝入數(shù)組,并且從數(shù)組的第26個(gè)開始裝入(letter[0]-letter[25]已被裝入了字母)
j++;
}
}
}
class display{
public static void main(String[] args){
char temp;
int t;
int[] n= new int [52]; //用于統(tǒng)計(jì)每個(gè)字符出現(xiàn)的次數(shù)
Check2 k =new Check2();
FuZhi m=new FuZhi();
for(int j=0;j52;j++){
t=0; //令t為0,,并且使上一個(gè)字母統(tǒng)計(jì)完成后
//將其再次初始化(如A統(tǒng)計(jì)完成后,當(dāng)程序統(tǒng)計(jì)B出現(xiàn)的次數(shù)時(shí),使B的初始次數(shù)為0)
for(int i=0;ik.t;i++){
if(m.letter[j]==k.chs[i]){ //比較字符是否相同,如相同,使t自加一
t++;
n[j]=t; //數(shù)組n來統(tǒng)計(jì)每個(gè)字母出現(xiàn)的次數(shù),即其中的每一個(gè)元素代表一個(gè)字母在程序中出現(xiàn)的次數(shù)
}
}
}
System.out.println("總共輸入了"+k.t+"個(gè)字符:\n"+"其中");
for(int i=0;i52;i++){
System.out.println("字母"+m.letter[i]+"出現(xiàn)的次數(shù)為:"+n[i]+"次");
}
}
}
寫掉了一句“l(fā)etter[i]=p;”,現(xiàn)在已經(jīng)補(bǔ)上了,程序可以運(yùn)行了,你試一下吧?。?!