---0522小考部分

 

import java.io.*;

import java.util.*;

public class test1 {

 

        public static void main(String args[])throws IOException

        {

            BufferedReader buf= new BufferedReader(new InputStreamReader(System.in));

            String str;

            System.out.println("請輸入NUM");

            str=buf.readLine();

            int num=Integer.parseInt(str);

           

            int a[]=new int[100], i;

            for(i=0;i<=1000;i++)

            {

                    System.out.println("請輸入數值");

                str=buf.readLine();//str為輸入字串

                if(str.equals("0")) break;

                //輸入的str存到陣列

                a[i]=Integer.parseInt(str);

            }

            int count=i-1, sum=0;

            for(i=0;i<=count;i++)

            {       System.out.print(a[i] + ",");

                    if(num==a[i]) sum +=1;

            }

           

            System.out.print( sum + ",");

           

            for(i=0;i<=count;i++)

            {      

                    if(a[i]>num) System.out.print(a[i] + ",");

            }

           

        }

}

---排序  由小到大

 

 

 

public class sort {
public static void main(String args[]) {
int a[] = { 100, 60, 150, 30, 20 }, i, j, temp;
//第1次迴圈最大值會排到最後面
//第2次迴圈最大值會排到倒數第2個
//第3次迴圈最大值會排到倒數第3個

for(int n=0;n<a.length;n++){ //第二次迴圈
for (i = 0; i < a.length -1; i++) {//排序由小到大
if (a[i] > a[i + 1])// 前項大於後項置換
{
temp = a[i]; // temp 前項
a[i] = a[i + 1]; // 前項+後項
a[i + 1] = temp;// 後項 = temp = 原前項
}
}
}

for (i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
}
}

 ---


public class class1 {
public static void main(String[] args) {
String str = "987650321";
String rev = "";
int i;
for( i = str.length()-1;i>=0;i--){
rev = rev+str.charAt(i);}
System.out.println(rev);
for(i = rev.length()-1;i>=0;i--){
if(i==9 && rev.charAt(i) !='0'){
System.out.println(" 拾億位數為:"+rev.charAt(i));}
if(i==8 && rev.charAt(i) !='0'){ System.out.println(" 億位數為:"+rev.charAt(i));}
if(i==7 && rev.charAt(i) !='0'){ System.out.println("仟萬位數為:"+rev.charAt(i));}
if(i==6 && rev.charAt(i) !='0'){ System.out.println("佰萬位數為:"+rev.charAt(i));}
if(i==5 && rev.charAt(i) !='0'){ System.out.println("拾萬位數為:"+rev.charAt(i));}
if(i==4 && rev.charAt(i) !='0'){ System.out.println(" 萬位數為:"+rev.charAt(i));}
if(i==3 && rev.charAt(i) !='0'){ System.out.println(" 仟位數為:"+rev.charAt(i));}
if(i==2 && rev.charAt(i) !='0'){ System.out.println(" 佰位數為:"+rev.charAt(i));}
if(i==1 && rev.charAt(i) !='0'){ System.out.println(" 拾位數為:"+rev.charAt(i));}

}

}
}

 

--Console

123056789
   億位數為:9
仟萬位數為:8
佰萬位數為:7
拾萬位數為:6
   萬位數為:5
   佰位數為:3
   拾位數為:2

----------------------------------------

 


public class class1 {
public static void main(String[] args) {
String str = "503210000";
String rev = "";
int i;
for( i = str.length()-1;i>=0;i--){
rev = rev+str.charAt(i);}
System.out.println(rev);//rev = "000012305"
for(i = rev.length()-1;i>=0;i--){
if(i==9 && rev.charAt(i) !='0'){
System.out.println(" 拾億位數為:"+rev.charAt(i));}
if(i==8 && rev.charAt(i) !='0'){ System.out.println(" 億位數為:"+rev.charAt(i));}
if(i==7 && rev.charAt(i) !='0'){ System.out.println("仟萬位數為:"+rev.charAt(i));}
if(i==6 && rev.charAt(i) !='0'){ System.out.println("佰萬位數為:"+rev.charAt(i));}
if(i==5 && rev.charAt(i) !='0'){ System.out.println("拾萬位數為:"+rev.charAt(i));}
if(i==4 && rev.charAt(i) !='0'){ System.out.println(" 萬位數為:"+rev.charAt(i));}
if(i==3 && rev.charAt(i) !='0'){ System.out.println(" 仟位數為:"+rev.charAt(i));}
if(i==2 && rev.charAt(i) !='0'){ System.out.println(" 佰位數為:"+rev.charAt(i));}
if(i==1 && rev.charAt(i) !='0'){ System.out.println(" 拾位數為:"+rev.charAt(i));}

}

for(i=0;i<rev.length();i++){
if(rev.charAt(i) !='0'){
break; //跳離迴圈
}

}
System.out.println("原字串:"+rev);
for(int j=i;j<rev.length();j++){
System.out.print(rev.charAt(j));

}
}
}

 

--Console

000012305
億位數為:5
佰萬位數為:3
拾萬位數為:2
萬位數為:1
原字串:000012305
12305

 

 

arrow
arrow
    全站熱搜

    玥君 發表在 痞客邦 留言(0) 人氣()