參考Java源代碼:
你所需要的網(wǎng)站建設(shè)服務(wù),我們均能行業(yè)靠前的水平為你提供.標(biāo)準(zhǔn)是產(chǎn)品質(zhì)量的保證,主要從事成都做網(wǎng)站、網(wǎng)站制作、成都外貿(mào)網(wǎng)站建設(shè)、企業(yè)網(wǎng)站建設(shè)、手機(jī)網(wǎng)站制作設(shè)計(jì)、網(wǎng)頁(yè)設(shè)計(jì)、品牌網(wǎng)站制作、網(wǎng)頁(yè)制作、做網(wǎng)站、建網(wǎng)站。創(chuàng)新互聯(lián)擁有實(shí)力堅(jiān)強(qiáng)的技術(shù)研發(fā)團(tuán)隊(duì)及素養(yǎng)的視覺(jué)設(shè)計(jì)專才。
import java.util.Scanner;
public class Test09 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
char start, end;
int delta;
int row, col;
int i, j;
do {
System.out.print("The first character: ");
start = scan.next().charAt(0);
System.out.print("The last character: ");
end = scan.next().charAt(0);
} while(start end);
delta = end - start + 1;
for(row=0; rowdelta; row++) {//控制圖案整體行數(shù)
//上三角形圖案
for(i=0; idelta; i++) {//控制一個(gè)圖案的一行
for(col=0; coldelta; col++) {//控制圖案整體列數(shù)
for(j=0; jdelta-1-i; j++) {//輸出前導(dǎo)空格
System.out.print(" ");
}
for(j=0; j2*i+1; j++) {//輸出字母
System.out.print((char)(start + i));
}
for(j=0; jdelta-1-i; j++) {//輸出后面空格
System.out.print(" ");
}
System.out.print("???? ");?? ?//輸出間隔
}
System.out.println();
}
//下三角形圖案
for(i=0; idelta-1; i++) {//控制一個(gè)圖案的一行
for(col=0; coldelta; col++) {//控制圖案整體列數(shù)
for(j=0; j=i; j++) {//輸出前導(dǎo)空格
System.out.print(" ");
}
for(j=0; j2*delta-3-2*i; j++) {//輸出字母
System.out.print((char)(start + delta - 2 - i));
}
for(j=0; j=i; j++) {//輸出后面空格
System.out.print(" ");
}
System.out.print("???? ");?? ?//輸出間隔
}
System.out.println();
}
System.out.println();
}
}
}
運(yùn)行測(cè)試:
package?test1;
import?java.util.Scanner;
public?class?Test?{
public?static?void?main(String[]?args){
Scanner?scanner?=?new?Scanner(System.in);
System.out.println("輸入數(shù)組1長(zhǎng)度");
int?n1?=?scanner.nextInt();
System.out.println("輸入數(shù)組1");
String?nullString1?=?scanner.nextLine();
String?numsString1?=?scanner.nextLine();
String[]?split1?=?numsString1.split("?");
System.out.println("輸入數(shù)組2長(zhǎng)度");
int?n2?=?scanner.nextInt();
System.out.println("輸入數(shù)組2");
String?nullString2?=?scanner.nextLine();
String?numsString2?=?scanner.nextLine();
String[]?split2?=?numsString2.split("?");
System.out.println("輸入條件");
String?numsString3?=?scanner.nextLine();
String[]?split3?=?numsString3.split("?");
int?start?=?Integer.valueOf(split3[0]);
int?mubiao?=?Integer.valueOf(split3[1]);
int?number?=?Integer.valueOf(split3[2]);
for(int?i?=?(mubiao-1),y=(start-1),c?=?0?;?c??number?;?i++,y++,c++){
split1[y]?=?split2[i];
}
for(int?i?=0?;?i??split1.length?;?i++){
System.out.print(split1[i]+"?");
}
}
}
你好,java的API中提供了用于對(duì)象輸入輸出文件的操作,實(shí)例代碼如下:
定義單詞類如下(注意:你定義的類要實(shí)現(xiàn)Serializable接口)
public class Words implements Serializable {
private int size;
private String[] words;
public Words(){};
public Words(String...strs){
this.words = strs;
this.size = strs.length;
}
@Override
public String toString() {
return "Words{" +
"size=" + size +
", words=" + Arrays.toString(words) +
'}';
}
}
2. 對(duì)象輸入輸出api測(cè)試類
public class ObjIOTest {
public static void main(String[] args) {
String path = "d:/myIOTest.txt";
ObjIOTest objIOTest = new ObjIOTest();
Words words = new Words("hello", "my", "dear", "friend");
try {
objIOTest.writeObject(path,words);
Words wordsFromFile = (Words)objIOTest.readObject(path);
System.out.println(wordsFromFile.toString());
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
}
//java serialize a object to file
public void writeObject(String path,Object map) throws IOException{
File f=new File(path);
FileOutputStream out=new FileOutputStream(f);
ObjectOutputStream objwrite=new ObjectOutputStream(out);
objwrite.writeObject(map);
objwrite.flush();
objwrite.close();
}
// read the object from the file
public Object readObject(String path) throws IOException, ClassNotFoundException{
FileInputStream in=new FileInputStream(path);
ObjectInputStream objread=new ObjectInputStream(in);
Object map=objread.readObject();
objread.close();
return map;
}
}
把兩段代碼拷貝到一個(gè)包下即可運(yùn)行了,希望您的問(wèn)題得到解答
public?class?Pyramid
{
public?static?void?main(String[]?args)
{
int?i=0,j=0,n=6,k=0;
for(i=0;?in;?i++)
{
k=1;
for(j=0;?j(n+i);?j++)
{
if(jn-i-1)
System.out.print("?");
else
{
System.out.print(""+k);
if(j(n-1))
k++;
else
k--;
}
}
System.out.println("?");
}
}
}
public class Person {
public String name;
public int age;
public Person(String name, int age){
this.name = name;
this.age = age;
}
public Person(String name){
this.name = name;
this.age = 20;
}
public void work(){
System.out.println("我正在工作!");
}
public static void main(String[] args) {
Person p = new Person("I");
p.work();
}
}
-------------------------------------------------------------
public class Person {
public String name;
public int age;
public Person(String name, int age){
this(name);
this.age = age;
}
public Person(String name){
this.name = name;
this.age = 20;
}
public void work(){
System.out.println("我正在工作!");
}
public static void main(String[] args) {
Person p = new Person("I");
p.work();
}
}
class Student extends Person{
public Student(String name){
super(name);
}
public void work(){
System.out.println("學(xué)生在學(xué)習(xí)!");
}
}
class Teacher extends Person{
public Teacher(String name){
super(name);
}
public void work(){
System.out.println("老師在授課!");
}
}
當(dāng)前名稱:大佬寫(xiě)的java代碼 JAVA寫(xiě)代碼
文章位置:http://jinyejixie.com/article18/dodoegp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、軟件開(kāi)發(fā)、用戶體驗(yàn)、電子商務(wù)、網(wǎng)頁(yè)設(shè)計(jì)公司、營(yíng)銷型網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)