参考Java源代码:
你所需要的网站建设服务,我们均能行业靠前的水平为你提供.标准是产品质量的保证,主要从事成都做网站、网站制作、成都外贸网站建设、企业网站建设、手机网站制作设计、网页设计、品牌网站制作、网页制作、做网站、建网站。创新互联拥有实力坚强的技术研发团队及素养的视觉设计专才。
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++) {//控制图案整体行数
//上三角形图案
for(i=0; idelta; i++) {//控制一个图案的一行
for(col=0; coldelta; col++) {//控制图案整体列数
for(j=0; jdelta-1-i; j++) {//输出前导空格
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++) {//控制一个图案的一行
for(col=0; coldelta; col++) {//控制图案整体列数
for(j=0; j=i; j++) {//输出前导空格
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();
}
}
}
运行测试:
package test1;
import java.util.Scanner;
public class Test {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("输入数组1长度");
int n1 = scanner.nextInt();
System.out.println("输入数组1");
String nullString1 = scanner.nextLine();
String numsString1 = scanner.nextLine();
String[] split1 = numsString1.split(" ");
System.out.println("输入数组2长度");
int n2 = scanner.nextInt();
System.out.println("输入数组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中提供了用于对象输入输出文件的操作,实例代码如下:
定义单词类如下(注意:你定义的类要实现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. 对象输入输出api测试类
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;
}
}
把两段代码拷贝到一个包下即可运行了,希望您的问题得到解答
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("学生在学习!");
}
}
class Teacher extends Person{
public Teacher(String name){
super(name);
}
public void work(){
System.out.println("老师在授课!");
}
}