import javax.swing.*;
class compute
{
long square(long x)
{
return x*x;
}
boolean[] binary(long x)
{
int bitN=(int)Math.ceil(Math.log(x+1)/Math.log(2));
boolean [] b=new boolean[bitN];
int i=bitN-1;
do
{
b[i--]=((x&1)==1)?true:false;
x=x>>1;
} while (x!=0);
for (i=0;i<bitN; i++)
System.out.print(b[i]?1:0);
System.out.println();
return b;
}
}
public class power
{
public static void main(String[] argv) throws Exception
{
compute math=new compute();
long x=new Long(JOptionPane.
showInputDialog("x=")).longValue();
boolean[] b=math.binary(x);
long y=math.square(x);
JOptionPane.showMessageDialog(null, x+"*"+x+"="+Long.toString(y));
}
}
herrDeng網內搜尋
自訂搜尋
Ads
2010年5月13日 星期四
Java檔案讀寫
import java.io.*;
import java.util.*;
class student
{
String name;
int number;
}
public class readWriteFile
{
public static void main(String [] args) throws IOException
{
student[] X=new student[26];
FileReader fr=new FileReader("student.txt");
BufferedReader bfr=new BufferedReader(fr);
String tmp;
for (int i=0;i<26;i++)
{
X[i]=new student();
tmp=bfr.readLine();
X[i].name=tmp;
X[i].number=(int)(100*Math.random());
}
fr.close();
FileWriter fw=new FileWriter("List.txt");
BufferedWriter bfw=new BufferedWriter(fw);
for (int k=0;k<26;k++)
{
System.out.print(k+":");
System.out.println(X[k].name+"\t"+X[k].number);
bfw.write(k+":"+X[k].name+"\t"+X[k].number);
bfw.newLine();
}
bfw.flush();
fw.close();
}
}
-------------------------------------------------------------------
林韋凱
鄭宇志
林挺生
林美君
彭聖媚
劉修駿
宋宏杰
吳俊昌
何啟維
湯志平
李逸翔
馬鴻岳
彭宇霆
黃羿綺
林香毓
陳秋茹
import java.util.*;
class student
{
String name;
int number;
}
public class readWriteFile
{
public static void main(String [] args) throws IOException
{
student[] X=new student[26];
FileReader fr=new FileReader("student.txt");
BufferedReader bfr=new BufferedReader(fr);
String tmp;
for (int i=0;i<26;i++)
{
X[i]=new student();
tmp=bfr.readLine();
X[i].name=tmp;
X[i].number=(int)(100*Math.random());
}
fr.close();
FileWriter fw=new FileWriter("List.txt");
BufferedWriter bfw=new BufferedWriter(fw);
for (int k=0;k<26;k++)
{
System.out.print(k+":");
System.out.println(X[k].name+"\t"+X[k].number);
bfw.write(k+":"+X[k].name+"\t"+X[k].number);
bfw.newLine();
}
bfw.flush();
fw.close();
}
}
-------------------------------------------------------------------
林韋凱
鄭宇志
林挺生
林美君
彭聖媚
劉修駿
宋宏杰
吳俊昌
何啟維
湯志平
李逸翔
馬鴻岳
彭宇霆
黃羿綺
林香毓
陳秋茹
Java亂數排序
相關講義
import java.security.SecureRandom;
import java.util.Arrays;
public class bubbleSort
{
static void bubbleSort(int [] data)
{
int temp;
for (int i=data.length-1; i>0; i--)
for (int j=0;j<i;j++)
if (data[j]>data[j+1])
{
temp=data[j];
data[j]=data[j+1];
data[j+1]=temp;
}
}
public static void main(String [] argv)
{
SecureRandom rnd=new SecureRandom();
int [] data=new int[26];
int a,b;
do
{
a=rnd.nextInt()%101;
if (a<0) a+=101;
} while (a==0);
b=rnd.nextInt()%101+101;
for (int i=0; i<26;i++)
{
data[i]=(a*i+b)%101;
System.out.print("data["+i+"]="+data[i]+"\t");
}
System.out.println("\nBefore Sorting!");
// bubbleSort(data);
Arrays.sort(data); //quick sort
for (int i=0;i<26;i++)
System.out.print("data["+i+"]="+data[i]+"\t");
System.out.println("\nAfter Sorting!");
}
}
import java.security.SecureRandom;
import java.util.Arrays;
public class bubbleSort
{
static void bubbleSort(int [] data)
{
int temp;
for (int i=data.length-1; i>0; i--)
for (int j=0;j<i;j++)
if (data[j]>data[j+1])
{
temp=data[j];
data[j]=data[j+1];
data[j+1]=temp;
}
}
public static void main(String [] argv)
{
SecureRandom rnd=new SecureRandom();
int [] data=new int[26];
int a,b;
do
{
a=rnd.nextInt()%101;
if (a<0) a+=101;
} while (a==0);
b=rnd.nextInt()%101+101;
for (int i=0; i<26;i++)
{
data[i]=(a*i+b)%101;
System.out.print("data["+i+"]="+data[i]+"\t");
}
System.out.println("\nBefore Sorting!");
// bubbleSort(data);
Arrays.sort(data); //quick sort
for (int i=0;i<26;i++)
System.out.print("data["+i+"]="+data[i]+"\t");
System.out.println("\nAfter Sorting!");
}
}
2010年5月4日 星期二
2010年4月21日 星期三
AES-192密文
AES-192
Mode=AES-ECB
Key=48C3B428 6FF421A4 A328E68A D9E542A4 5D07291B 0B73E5EB 2FBDDA93 4EC4346C
Cipher= CE6907E1877033D36B199B6821CAD630322C0AB5D0621ED308FAFA171279C86D
解密:
hint:
#include <stdio.h>
#include <stdlib.h>
#include <cryptoki.h>
#include <string.h>
int main()
{
char HEX[]="48C3B4286FF421A4A328E68AD9E542A45D07291B0B73E5EB2FBDDA934EC4346C";
CK_BYTE key[32];
char tmp[3];
for (int i=0; i<32; i++)
{
tmp[0]=HEX[2*i];
tmp[1]=HEX[2*i+1];
tmp[2]='\0';
sscanf(tmp, "%x", &key[i]);
printf("%#3x ", key[i]);
}
system("Pause");
return 0;
}
Mode=AES-ECB
Key=48C3B428 6FF421A4 A328E68A D9E542A4 5D07291B 0B73E5EB 2FBDDA93 4EC4346C
Cipher= CE6907E1877033D36B199B6821CAD630322C0AB5D0621ED308FAFA171279C86D
解密:
hint:
#include <stdio.h>
#include <stdlib.h>
#include <cryptoki.h>
#include <string.h>
int main()
{
char HEX[]="48C3B4286FF421A4A328E68AD9E542A45D07291B0B73E5EB2FBDDA934EC4346C";
CK_BYTE key[32];
char tmp[3];
for (int i=0; i<32; i++)
{
tmp[0]=HEX[2*i];
tmp[1]=HEX[2*i+1];
tmp[2]='\0';
sscanf(tmp, "%x", &key[i]);
printf("%#3x ", key[i]);
}
system("Pause");
return 0;
}
2010年4月14日 星期三
2010年4月6日 星期二
2010年4月1日 星期四
世界程式語言排名
| Programming Language | Position Mar 2010 | Position Mar 2006 | Position Mar 2000 | Position Mar 1985 |
|---|---|---|---|---|
| Java | 1 | 1 | 3 | - |
| C | 2 | 2 | 2 | 1 |
| PHP | 3 | 4 | 14 | - |
| C++ | 4 | 3 | 1 | 9 |
| (Visual) Basic | 5 | 5 | 4 | 3 |
| C# | 6 | 7 | 22 | - |
| Python | 7 | 8 | - | - |
| Perl | 8 | 6 | 5 | - |
| Delphi | 9 | 9 | 7 | - |
| JavaScript | 10 | 10 | 13 | - |
感謝林孟文老師告知,資料取於http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
2010年3月18日 星期四
訂閱:
文章 (Atom)
熱門文章
-
C++用 -1 mask法達到branchless解Leetcode1513 Number of Substrings With Only 1s|Py3 1-liner 其實很容易,想練功,試試一行解,或是把if分岔拿掉 [C++無分岔解請進]
-
請用C/C++ 程式計算 S=1*1+2*2+3*3+4*4+.....+20*20=?
-
計算你上學期加權平均
-
問int怎麼存-689這個數字。 int用4個bytes。 答案請用16進位表達。
-
計算你的BMI
-
何謂演算法?並列出一無窮迴圈的範例!
-
將費氏數列輸出至一long 陣列 其中f[0]=1, f[1]=2, f[n]=f[n-1]+f[n-2] (n>=2)
-
算上學期加權平均
-
請問你所使的電腦,CPU的規格 Cache多大?其他硬體配置...... 另外, "INTEL® XEON PHI™ 處理器 7230F"的大致規格為?
-
列印課表數字代碼矩陣,以及代碼的課名 提示: 參考此連結

