java在線編譯器-youjavait.com
posted on 2009-12-26 02:40 funja 閱讀(11570) 評(píng)論(27) 編輯 收藏
posted on 2009-12-26 02:40 funja 閱讀(11570) 評(píng)論(27) 編輯 收藏
class test{
static int x=5;
static{x+=10;}
public static viod main (String args[]){
System.out.println('x='+x)
}
statilc{x=x-5;}
} 回復(fù) 更多評(píng)論
public static int mcCarthy(int n) {
if (n > 100) return n - 10;
else return mcCarthy(mcCarthy(n+11));
}
回復(fù) 更多評(píng)論
學(xué)習(xí)java 回復(fù) 更多評(píng)論
希望對(duì)我有用 回復(fù) 更多評(píng)論
//需求:用switch語句實(shí)現(xiàn)四季的選擇
class SwitchDemo
{
public static void main(String[] args)
{
int i=7;
switch (i)
{
case 3:
case 4:
case 5:
System.out.println(i+"春季");
break;
case 6:
case 7:
case 8:
System.out.println(i+"夏季");
break;
case 9:
case 10:
case 11:
System.out.println(i+"秋季");
break;
case 12:
case 1:
case 2:
System.out.println(i+"冬季");
}
}
} 回復(fù) 更多評(píng)論
class test{
String s = "Hello";
public static viod main (String args[]){
String[] str = s.split("A");
System.out.println(str);
}
} 回復(fù) 更多評(píng)論
class SwitchDemo
{
public static void main(String[] args)
{
int i=7;
switch (i)
{
case 3:
case 4:
case 5:
System.out.println(i+"春季");
break;
case 6:
case 7:
case 8:
System.out.println(i+"夏季");
break;
case 9:
case 10:
case 11:
System.out.println(i+"秋季");
break;
case 12:
case 1:
case 2:
System.out.println(i+"冬季");
}
}
} 回復(fù) 更多評(píng)論
int a; 回復(fù) 更多評(píng)論
class SwitchDemo
{
public static void main(String[] args)
{
int i=7;
switch (i)
{
case 3:
case 4:
case 5:
System.out.println(i+"春季");
break;
case 6:
case 7:
case 8:
System.out.println(i+"夏季");
break;
case 9:
case 10:
case 11:
System.out.println(i+"秋季");
break;
case 12:
case 1:
case 2:
System.out.println(i+"冬季");
}
}
} 回復(fù) 更多評(píng)論
修改JEMail應(yīng)用程序包括一個(gè)明確的按鈕,用戶可以單擊隨時(shí)清除“;”、“主題;”、“消息;”字段。保存文件為JEMail2.java 回復(fù) 更多評(píng)論
public class Test{
publilc static void main(String[] args){
System.out.print("i love you");
}
}
回復(fù) 更多評(píng)論
class A{
public static int a1;
public int a2;
}
public class Test{
public static void main(String[] args){
A t1=new A();
t1.a1=4;
t1.a2=5;
A t2=new A();
t2.a1=6;
t2.a2=7;
System.out.println(t1.a1+","+t1.a2);
System.out.println(t2.a1+","+t2.a2);
}
}
回復(fù) 更多評(píng)論
public class Main {
System.out.println("######## ## ## ## ## ###### ######
## ## ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ##
# ## ## ## ## ## ##
## ## ## ## ## ## ## ## ##
## ## ## ####### ###### ######");
} 回復(fù) 更多評(píng)論
public class Test {
int x, y;
Test(int x, int y) {
this.x = x;
this.y = y;
}
public static void main(String[] args) {
Test pt1, pt2;
pt1 = new Test(3, 3);
pt2 = new Test(4, 4);
System.out.print(pt1.x + pt2.x);
}
}
回復(fù) 更多評(píng)論
public class Test {
public static void main(String[] args){
System.out.println("abcdefg");
}
} 回復(fù) 更多評(píng)論
Package
public class Name{
/*自己的介紹*/
public static void main(String[]args){
System.out.print("你好,我是青鳥學(xué)員\n";);
System.out.print("姓名:愛編程");
System.out.print("年齡:20歲");
System.out.print("愛好:打籃球");
}
} 回復(fù) 更多評(píng)論
class Course //定義課程類
{
private int code; //設(shè)置課程代碼屬性
private String name; //設(shè)置課程名稱屬性
private int time; //設(shè)置學(xué)時(shí)屬性
private int credit; //設(shè)置學(xué)分屬性
private String classification; //設(shè)置課程類別屬性
int getCode() //獲取課程代碼
{
return code;
}
void setCode(int code) //設(shè)置課程代碼
{
this.code=code;
}
String getName() //獲取課程名稱
{
return name;
}
void setName(String name) //設(shè)置課程名稱
{
this.name=name;
}
int getTime() //獲取學(xué)時(shí)
{
return time;
}
void setTime(int time) //設(shè)置學(xué)時(shí)
{
this.time=time;
}
int getCredit() //獲取學(xué)分
{
return credit;
}
void setCredit(int credit) //設(shè)置學(xué)分
{
this.credit=credit;
}
String getClassification() //獲取課程類別
{
return classification;
}
void setClassification(String classification) //設(shè)置課程類別
{
this.classification=classification;
}
public static void main(String [] args) //主函數(shù)測(cè)試
{
Course course1=new Course(); //課程1測(cè)試
course1.setCode(1101);
course1.setName("毛概");
course1.setTime(70);
course1.setCredit(6);
course1.setClassification("社會(huì)主義");
System.out.println("課程代碼:"+course1.getCode()); //課程1打印輸出
System.out.println("課程名稱:"+course1.getName());
System.out.println("課程類別:"+course1.getClassification());
System.out.println("學(xué)時(shí):"+course1.getTime());
System.out.println("學(xué)分:"+course1.getCredit());
System.out.println("\n");
Course course2=new Course(); //課程2測(cè)試
course2.setCode(0420);
course2.setName("思修");
course2.setTime(60);
course2.setCredit(4);
course2.setClassification("社會(huì)主義");
System.out.println("課程代碼:"+course2.getCode()); //課程2打印輸出
System.out.println("課程名稱:"+course2.getName());
System.out.println("課程類別:"+course2.getClassification());
System.out.println("學(xué)時(shí):"+course2.getTime());
System.out.println("學(xué)分:"+course2.getCredit());
}
} 回復(fù) 更多評(píng)論
小明左,右手中分別拿著兩張牌:黑桃10和紅桃8.現(xiàn)在交換手中的牌,用程序模擬這一個(gè)過程;兩個(gè)整數(shù)分別保存在兩個(gè)變量中,講著兩個(gè)變量的值互換,并輸出互換后的結(jié)果。 回復(fù) 更多評(píng)論
定義一個(gè)類Students,繼承自類Person,新增成員變量StdNo(學(xué)號(hào)),重寫成員方法ShowName,顯示當(dāng)前學(xué)生的“學(xué)號(hào)+姓名”。 回復(fù) 更多評(píng)論
public class A
{
public static void main(String args[])
{
String s1="java";
String s2="JavA";
System.out.println(s1.compareTo(s2));
System.out.println(s1.compareToIgnoreCase(s2));
}
} 回復(fù) 更多評(píng)論
public class TestOnline {
public static void main(String[] args){
System.out.println("TestOnline ");
} 回復(fù) 更多評(píng)論
public class Hello
{
public static void main(String []args)
{
System.out.printIn("Hello world");
}
}
回復(fù) 更多評(píng)論
import jsva.util.Scanner;
import java.util.*;
public class ProductCodes {
public static void main(String[] args)
{
String code;
char zone;
int district,valid=0,banned=0;
Scanner scan=new Scanner (System.in);
System.out.print("Enter product code (XXX to quit):");
code=scan.nextLine();
while(!(code.equals("XXX")))
{
try
{
zone=code.charAt(9);
district=Integer.parseInt(code.substring(3,7));
valid++;
if(zone=='R'&&district>2000)
banned++;
}
catch(StringIndexOutOfBoundsException exception)
{
System.out.println("Improper code length: "+code);
}
catch(NumberFormatException exception)
{
System.out.println("District is not numeric:"+code);
}
System.out.print("Enter product code (XXX to quit):");
code=scan.nextLine();
}
System.out.println("# of valid codes entered:"+valid);
System.out.println("# of banned codes entered:"+banned);
}
}
回復(fù) 更多評(píng)論
public class Main{
public static void main(String[] args){
int A=3;
int B=2;
System.out.println("3 + 2 = "+(A+B));
System.out.println("3 - 2 = "+(A-B));
System.out.println("3 * 2 = "+(A*B));
System.out.println("3 / 2 = "+(A/B));
}
} 回復(fù) 更多評(píng)論
public class People {
private int number;
private String name;
private String sex;
private int age;
public People(){}
public People(int number,String name,String sex,int age){
this.name=name;
this.age=age;
this.number=number;
this.sex=sex;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public static void main(String []ad){
People pp= new People(001,"張三","男",23);
System.out.println("編號(hào):"+pp.getNumber());
System.out.println("名字:"+pp.getName());
System.out.println("年齡:"+pp.getAge());
System.out.println("性別:"+pp.getSex());
}
} 回復(fù) 更多評(píng)論
class Main
{
public static void main (String[] args)
{
Fuck f = new Fuck();
Thread t = new Thread(f);
t.start();
}
}
class Fuck implements Runnable
{
public void run(){
while(true){
System.out.println("fuck");
}
}
} 回復(fù) 更多評(píng)論
import java.io.BufferedOutputStream;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.FileReader;import java.io.IOException;import java.io.PrintWriter;import java.util.Scanner;public class AddList { private String filePath = ""; private String bakPath = ""; private String content = ""; Scanner sc = new Scanner(System.in); public String readFile(){ content = ""; if (isNull(filePath)) { System.out.println("文件存儲(chǔ)路徑:"); filePath = sc.nextLine(); } File file = new File(filePath); FileReader fr = null; try { if (file.exists()) { fr = new FileReader(file); char[] chars = new char[1024]; int n = 0; while((n = fr.read(chars)) != -1){ String string = new String(chars, 0, n); content = content + string; } } else { System.out.println("文件不存在"); } } catch (Exception e) { e.printStackTrace(); } finally { if (fr != null) { try { fr.close(); } catch (IOException e) { e.printStackTrace(); } } } return content; } public void writeFile(String path){ File file = new File(path); FileOutputStream fos = null; mkDirs(path); try { fos = new FileOutputStream(file); BufferedOutputStream bos = new BufferedOutputStream(fos); PrintWriter pw = new PrintWriter(bos, true); pw.print(content); pw.flush(); } catch (FileNotFoundException e) { e.printStackTrace(); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } } } public void writeFile(){ if (isNull(filePath)) { System.out.println("文件存儲(chǔ)路徑:"); filePath = sc.nextLine(); } File file = new File(filePath); FileOutputStream fos = null; mkDirs(filePath); try { fos = new FileOutputStream(file); BufferedOutputStream bos = new BufferedOutputStream(fos); PrintWriter pw = new PrintWriter(bos, true); pw.print(content); pw.flush(); } catch (FileNotFoundException e) { e.printStackTrace(); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } } } public void mkDirs(String filepath){ if (filepath.indexOf("\\") != -1) { filepath = filepath.replaceAll("\\", "/"); } int n = filepath.indexOf("//"); String path = filepath.substring(0, n) + "//"; filepath = filepath.substring(filepath.indexOf("//") + 1, filepath.length()); String[] files = filepath.split("/"); for (int i = 0; i < files.length - 1; i++) { path = path + files[i]; File file = new File(path); if (!file.exists()) { file.mkdir(); } } } public void addImfor(){ System.out.println("--------增加記錄---------"); String name = ""; String tel = ""; String email = ""; content = readFile(); while(true){ System.out.println("姓名:"); name = sc.next(); System.out.println("電話:"); tel = sc.next(); System.out.println("Email:"); email = sc.next(); content = content + name + "<>" + tel + "<>" + email +"<==>"; System.out.println("0、Exit 1、繼續(xù)"); int i = sc.nextInt(); if (i == 0) { break; } } writeFile(); } public void deleteImfor(){ System.out.println("---------刪除記錄---------"); String name = ""; String[] imfors = null; content = readFile(); while(true){ System.out.println("你要?jiǎng)h除的姓名是:"); name = sc.next(); if (content.indexOf(name) != -1) { imfors = content.split("<==>"); for (int i = 0; i < imfors.length; i++) { if (imfors[i].indexOf(name) != -1) { imfors[i] = ""; } } 回復(fù) 更多評(píng)論
只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。 | ||
![]() |
||
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
|
||