package?Test;
成都創(chuàng)新互聯(lián)公司是專業(yè)的金湖網(wǎng)站建設公司,金湖接單;提供網(wǎng)站設計制作、做網(wǎng)站,網(wǎng)頁設計,網(wǎng)站設計,建網(wǎng)站,PHP網(wǎng)站建設等專業(yè)做網(wǎng)站服務;采用PHP框架,可快速的進行金湖網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!
import?java.io.BufferedReader;
import?java.io.File;
import?java.io.FileInputStream;
import?java.io.FileNotFoundException;
import?java.io.FileReader;
import?java.io.IOException;
import?java.io.InputStream;
import?java.io.InputStreamReader;
import?java.io.Reader;
import?java.io.StringBufferInputStream;
import?java.io.StringReader;
import?java.util.Scanner;
class?Test?{
private?static?Node?firstList,?secondList,?resultList;
private?static?void?input(Node?head)?throws?Exception?{
int?a;
int?b;
int?i;
Node?p?=?head;
BufferedReader?reader?=?new?BufferedReader(new?InputStreamReader(
System.in));
//?讀取一行信息
String?input?=?reader.readLine();
//?以空格為分隔符,轉(zhuǎn)換成數(shù)組
String[]?numbers?=?input.split("?");
for(i=0;inumbers.length;){
a?=?Integer.parseInt(numbers[i]);
b?=?Integer.parseInt(numbers[i+1]);
p.next?=?new?Node(a,?b);
p?=?p.next;
i+=2;
}
}
public?static?void?main(String[]?args)?throws?Exception?{
firstList?=?new?Node();
secondList?=?new?Node();
resultList?=?new?Node();
Node?p=resultList;
System.out.println("輸入第一個多項式");
input(firstList);
System.out.println("輸入第二個不等式");
input(secondList);
while(firstList.next!=nullsecondList.next!=null){
if(firstList.next.zssecondList.next.zs){
p.next=new?Node(firstList.next.xs,firstList.next.zs);
p=p.next;
firstList=firstList.next;
}else?if(firstList.next.zssecondList.next.zs){
p.next=new?Node(secondList.next.xs,secondList.next.zs);
p=p.next;
secondList=secondList.next;
}else{
p.next=new?Node(firstList.next.xs+secondList.next.xs,firstList.next.zs);
p=p.next;
firstList=firstList.next;
secondList=secondList.next;
}
}
if(firstList!=null){
p.next=firstList.next;
}
if(secondList!=null){
p.next=secondList.next;
}
p=resultList;
while(p.next!=null){
System.out.print(p.next.xs+"x^"+p.next.zs+"+");
p=p.next;
}
System.out.println();
}
}
public?class?Node?{
public?int?xs;//系數(shù)
public?int?zs;//指數(shù)
public?Node?next=null;//指向下一個
public?Node(int?a,int?b)?{
xs=a;
zs=b;
}
public?Node(){
}
}
答案
輸入第一個多項式
5 4 3 2 1 1
輸入第二個不等式
4 4 3 2 1 1
9x^4+6x^2+2x^1
android 使兩個按鈕水平排列的方法是使用lineLayout線性布局,如下代碼:
?xml?version="1.0"?encoding="utf-8"?
LinearLayout?xmlns:android=""
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="@color/background"
android:orientation="vertical"?
View
android:layout_width="wrap_content"
android:layout_height="1.2px"
android:layout_marginBottom="7dp"
android:background="@color/white"?/
LinearLayout
android:layout_width="fill_parent"
android:layout_height="79dp"
android:layout_weight="2"
android:orientation="horizontal"
android:layout_margin="10dp"?
Button
android:id="@+id/bt1"
android:layout_width="fill_parent"
android:layout_height="26dp"
android:background="@drawable/shape"
android:layout_weight="1"
android:text="確認對沖"
android:textColor="@color/white"
android:textSize="15dp"?/
Button
android:layout_width="fill_parent"
android:layout_height="26dp"
android:background="@drawable/shapeyuanjiao"
android:layout_weight="1"
android:text="取消"
android:textColor="@color/white"
android:textSize="15dp"?/
/LinearLayout
/LinearLayout
運行結(jié)果如下:
當你在main函數(shù)中add("Jack");時調(diào)用了SequenceList類的boolean add(Object obj)方法,該方法又調(diào)用了boolean add(int index, Object obj)方法,而這個方法的最后將size的值加1(size++),所以每次添加元素都會改變size的值。