求详解代码 hashmap和hashtablee sqls = new hashmap和hashtablee(); for (int i = 0; i < tuiyaoGridView2.RowCount - 1;i++ )

一个相当复杂的java编程题目!_百度知道
一个相当复杂的java编程题目!
我是一个在国外读书的大一新生,请各路高手帮我做一下这道复杂的java编程,多谢了!创建以下程式,然后把它们按顺序放入主程式。每个程式需要一个或多个辅助程式。注释:对于每种程式,你需要有合适的参数。程式一:名称:initialize(parameters)内容:创建一个长度为10的array,并随机给每一个元素配以1-10之间的任意数值。程式二:名称:printArray (parameters)内容:把程式一的内容打在屏幕上。程式三:名称:reverseArray (parameters)内容:将程式一中的array倒置,然后再打在屏幕上。程式四:名称:sumArray (parameters)内容:创建一个和程式一中相同大小的array,算出元素从0到j的总合,然后把结果放入新的array的j元素中。例如你有{4, 6, 3, 5}则新array就是{4, 10, 13, 18}。最后把新array打在屏幕上。程式五:名称:itilialize (parameters)内容:创建一个新程式,要长度50的array,然后从10-20的取值范围之间随机给每个元素配以数值。程式六:名称:countArray (parameters)内容:将程式五的array通过本程式,计算每个数字出现的次数,然后把结果打在屏幕上。程式七:名称:readArray (parameters)内容:创建一个字母的array, 读取键盘打入的字母,并储存在本array中。程式八:名称:printOneInLine(parameters)内容:将程式七中的array通过本程式,把其文字信息写成一行打在屏幕上。
提问者采纳
  package TestP  import java.io.BufferedR  import java.io.IOE  import java.io.InputStreamR  import java.util.ArrayL  import java.util.A  import java.util.H  import java.util.R  /**  * @author songml  *  */  public class ArrayTest {  /**  * @param args  */  public static void main(String args[]) {  ArrayList arrayListTest = new ArrayList();  arrayListTest = initialize(10);  System.out.println(&printArray:&);  printArray(arrayListTest);  System.out.println(&reverseArray:&);  reverseArray(arrayListTest);  System.out.println(&sumArray:&);  sumArray(arrayListTest);  System.out.println(&itilialize:&);  arrayListTest = itilialize(50);  printArray(arrayListTest);  System.out.println(&countArray:&);  countArray(arrayListTest);  System.out.println(&readArray:&);  arrayListTest = readArray();  printOneInLine(arrayListTest);  }  private static void printOneInLine(ArrayList array) {  System.out.println(&您输入的字母是:&+array);  }  private static ArrayList readArray() {  InputStreamReader i = new InputStreamReader(System.in);  BufferedReader distream = new BufferedReader(i);  ArrayList arrayListTest = new ArrayList();  System.out.println(&请输入一行字母&);  String s1 = &&;  try {  s1 = distream.readLine();  } catch (IOException e) {  e.printStackTrace();  }  arrayListTest.add(s1);  return arrayListT  }  /**  * @param intparameters  * @return arrayList  */  public static ArrayList initialize(int intparameters) {  ArrayList arrayList = new ArrayList();  Random rnd = new Random();  int x = 0;  for (int i=0; i & i++) {  x = rnd.nextInt(intparameters);  arrayList.add(String.valueOf(x+1));  }  return arrayL  }  /**  * @param intparameters  * @return ArrayList  */  public static ArrayList itilialize(int intparameters) {  ArrayList arrayList = new ArrayList();  Random rnd = new Random();  int x = 0;  for (int i=0; i & i++) {  x = rnd.nextInt(11);  arrayList.add(String.valueOf(10+x));  }  return arrayL  }  /**  * @param array  */  public static void countArray (ArrayList array) {  Hashtable hashTable = new Hashtable();  for (int i = 10;i &=20 ;i++ ) {  int count=0;  while (array.contains(String.valueOf(i))) {  array.remove(String.valueOf(i));  count ++;  }  hashTable.put(String.valueOf(i), String.valueOf(count));  }  for (int i = 10;i &=20 ;i++) {  System.out.print(i+&的个数:&+hashTable.get(String.valueOf(i))+&,&);  }  System.out.println();  }  /**  * @param array  */  public static void printArray(ArrayList array) {  System.out.println(array);  }  /**  * @param array  */  public static void reverseArray(ArrayList array) {  O  for(int i = 0 ;i & array.size()/2;i++) {  int intReverse = array.size()-1-i;  temp = array.get(i);  array.set(i, array.get(intReverse));  array.set(intReverse,temp);  }  System.out.println(array);  }  /**  * @param array  */  public static void sumArray(ArrayList array) {  ArrayList arrayListTemp = new ArrayList();  arrayListTemp =  for(int i = 0 ;i & array.size();i++) {  if (i & 0) {  int tempSum = Integer.parseInt(arrayListTemp.get(i-1).toString())  +Integer.parseInt(array.get(i).toString());  arrayListTemp.set(i, String.valueOf(tempSum));  }  }  System.out.println(arrayListTemp);  }  }  写了好久,,终于写完了!!
提问者评价
写法超过我的理解高度啦~不过还是给100分啦~
其他类似问题
java编程的相关知识
您可能关注的推广回答者:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁帮忙修改一个简单的java程序_百度知道
提问者采纳
import java.awt.BorderLimport java.awt.Bimport java.awt.CardLimport java.awt.Cimport java.awt.Fimport java.awt.GridLimport java.awt.Limport java.awt.Pimport java.awt.TextFimport java.awt.event.ActionEimport java.awt.event.ActionLimport java.awt.event.KeyEimport java.awt.event.KeyLimport java.awt.event.WindowAimport java.awt.event.WindowEimport java.util.Hpublic class frame { Frame f = new Frame(&Fancy Grocery&); Panel p = new Panel(); Panel p1 = new Panel(); Panel p2 = new Panel(); Panel p3 = new Panel(); Label costLabel = new Label(&COST&); Label massLabel = new Label(&MASS&); TextField costTextField = new TextField(); TextField massTextField = new TextField(); Button lemonsButton = new Button(&Lemons&); Button orangesButton = new Button(&Oranges&); Button strawberyButton = new Button(&Strawbery&); Button pearsButton = new Button(&Pears&); Button applesButton = new Button(&Apples&); Button peachesButton = new Button(&Peaches&); Button avocadosButton = new Button(&Avocados&); Button bananasButton = new Button(&Bananas&); Button cherryButton = new Button(&Cherry&); Button BT10 = new Button(&
&); Button BT11 = new Button(&
&); Button BT12 = new Button(&
&); Button weightButton = new Button(&WEIGHT&); Button printButton = new Button(&PRINT&); Button closeButton = new Button(&CLOSE&); Button[] BT = { lemonsButton, orangesButton, strawberyButton, pearsButton,
applesButton, peachesButton, avocadosButton, bananasButton,
cherryButton, BT10, BT11, BT12, weightButton, printButton,
closeButton }; private double costD public frame() {
f.setLayout(new CardLayout());
f.add(p, &&);// +++++
costLabel.setAlignment(Label.RIGHT);
massLabel.setAlignment(Label.LEFT);
costTextField.setEditable(false);
// costTextField.addActionListener(new textfield());
costTextField.setText(&0&);
massTextField.setEditable(false);
// massTextField.addActionListener(new textfield());
massTextField.addKeyListener(new VerifyInputKeyAdapter());
massTextField.setText(&0&);
p.setLayout(new BorderLayout());
p.add(p1, BorderLayout.CENTER);
p.add(p2, BorderLayout.NORTH);
p.add(p3, BorderLayout.SOUTH);
p1.setBackground(Color.blue);
p1.setLayout(new GridLayout(5, 3));
p2.setLayout(new GridLayout());
p2.add(costLabel);
p2.add(costTextField);
p3.setLayout(new GridLayout());
p3.add(massTextField);
p3.add(massLabel);
for (int i = 0; i & 15; i++) {
p1.add(BT[i]);
for (int j = 0; j & 9; j++) {
BT[j].addActionListener(new button());
BT[9].addActionListener(new blank());
BT[10].addActionListener(new blank());
BT[11].addActionListener(new blank());
BT[12].addActionListener(new weight());
BT[13].addActionListener(new print());
BT[14].addActionListener(new close());
f.setSize(450, 280);
f.setResizable(false);
f.setVisible(true);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(1);
}); } public static void main(String[] args) {
frame frame = new frame(); } class button implements ActionListener {
public void actionPerformed(ActionEvent e) {
Price p0 = new Price();
Double d = (Double) p0.ht.get(e.getActionCommand());
// System.out.println(d.toString());
costTextField.setText(d.toString());
massTextField.setEditable(false);
costDouble =
} } class weight implements ActionListener {
public void actionPerformed(ActionEvent e) {
massTextField.setEditable(true);
} } class textfield implements ActionListener {
public void actionPerformed(ActionEvent e) {
} } class VerifyInputKeyAdapter implements KeyListener {
public void keyTyped(KeyEvent e) {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() != KeyEvent.VK_BACK_SPACE) {
char inputChar = e.getKeyChar();
String input = Character.toString(inputChar);
if (!input.matches(&\\d&)) {
e.consume();
String masString = massTextField.getText();
int massInt = Integer.parseInt(masString + input);
double costs = massInt * costD
costTextField.setText(&& + costs);
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
String masString = massTextField.getText();
int massInt = Integer.parseInt(masString.equals(&&) ? &0&
: masString);
double costs = massInt * costD
costTextField.setText(&& + costs);
} }}class print implements ActionListener { public void actionPerformed(ActionEvent e) { }}class close implements ActionListener { public void actionPerformed(ActionEvent e) {
System.exit(1); }}class blank implements ActionListener { public void actionPerformed(ActionEvent e) { }}class Price { H public Price() {
ht = new Hashtable();
ht.put(&Apples&, new Double(6.00));
ht.put(&Pears&, new Double(5.00));
ht.put(&Oranges&, new Double(7.00));
ht.put(&Bananas&, new Double(3.00));
ht.put(&Lemons&, new Double(10.00));
ht.put(&Peaches&, new Double(4.00));
ht.put(&Strawberry&, new Double(4.00));
ht.put(&Cherry&, new Double(12.50));
ht.put(&Avocados&, new Double(15.00)); }}基本上满足你的要求了……你的代码我给你提点意见吧:1、你变量的命名要符合java的规范,比如说applesButton一看就知道是苹果的按钮,你原来写什么BT2BT3看起来很累的。2、类的名字最好大写开头。你先看着不明白再问我
你定义的costDouble是double的,我那个button里的d是Double的,2个不能=哦。还有就是我运行起来比如点apples之后,cost里是单价,我再点weight输入重量,但cost里不显示总价啊。还有print的功能,我想点一下之后可以将购物单打出来,该怎么弄??灰常感谢!!!还有那个你加的那个class我不是很明白。那个\\d是干嘛呢?e.getKeyCode() != KeyEvent.VK_BACK_SPACE又是干嘛呢?
double和Double可以直接=吧?我用的是eclipse3.3和jdk1.6是可以的你说不显示总价,你看看我这边运行的截图。购物单功能你可以用一个map来保存数据 然后在打出来KeyListener 是一个按键的监听器接口 在你按任何一个键的时候触发
提问者评价
太感谢了,收益匪浅!!!!
其他类似问题
java程序的相关知识
您可能关注的推广
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁C#图片加水印的问题_百度知道
C#图片加水印的问题
最近做了一个Winform程序要用到给图片加水印可是自已不是很懂,我是初学者
水印的相关知识
您可能关注的推广
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁如何判断一个数组中相同数的个数?比如int[]nums=new int[5]{1,1,3,1,3}.1有三个,3有两个,C#该怎么判断呢_百度知道
如何判断一个数组中相同数的个数?比如int[]nums=new int[5]{1,1,3,1,3}.1有三个,3有两个,C#该怎么判断呢
提问者采纳
linq&一句话搞定int[]&nums&=&new&int[5]&{&1,&1,&3,&1,&3&};var&d&=&from&n&in&nums&group&n&by&n&into&g&select&new&{&Key&=&g.Key,&Count&=&g.Count()&};
提问者评价
其他类似问题
写的不是很好,希望对你有所帮助int[] nNumlist = new int[] { 1, 2, 3, 4, 1, 1, 1, 2, 3, 4 };Array.Sort(nNumlist);int nTemp = nNumlist[0];int nCount = 0;for (int i = 0; i & nNumlist.L i++){
if (nTemp != nNumlist[i])
Console.WriteLine(&Count of Number {0} is {1}&, nTemp, nCount);
nTemp = nNumlist[i];
nCount = 1;
if (i == nNumlist.Length - 1)
Console.WriteLine(&Count of Number {0} is {1}&, nNumlist[i], nCount);
按默认排序
其他1条回答
int[] a = new int[] { 1,1,2,4,6,6,3,1};Hashtable ht = new Hashtable();for (int i = 0; i & a.L i++){int b = a[i];int count = 0;int flag = 0;#region 判断哈希表中已经存在该值,如果已存在,不再进行比较if (ht.Count & 0){foreach (System.Collections.DictionaryEntry de in ht){if (de.Key.ToString() == a[i].ToString()){flag = 1;}}if (flag == 1){}}#endregion#region 比较,和b相同的值有几个,写入哈希表for (int j = 0; j & a.L j++){if (i != j){if (b == a[j]){count++;}}}ht.Add(b.ToString(), count.ToString());#endregion}#region 输出结果string result = "结果:&br/&";foreach (System.Collections.DictionaryEntry de in ht){result += de.Key.ToString() + "有" + de.Value.ToString() + "个相同&br/&";}#endregionResponse.Write(result);结果:4有0个相同6有1个相同1有2个相同2有0个相同3有0个相同
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁CheckBoxList上从数据库上绑了很多值,然后我想把钩选的那些项都写据库的表中_百度知道
CheckBoxList上从数据库上绑了很多值,然后我想把钩选的那些项都写据库的表中
在这个表中分别记录选中的每一项.请问如何实现,具体的语句怎么写?谢谢
提问者采纳
/// &summary&
/// 获取所有选择了的角色
/// &/summary&
/// &param name=&al&&&/param&
protected string GetCheckRole()
string roidStr = &&;
for (int i = 0; i & chklsRoleList.Items.C i++)
if (chklsRoleList.Items[i].Selected)
roidStr += chklsRoleList.Items[i].Value.ToString() + &,&;
if (roidStr != &&)
roidStr = &,& + roidS
return roidS
}不知道有没有对你起到帮助补充:在表中存放就按照页面上取道的字符串存到一个字段里就行 如 1,2,3编辑的时候,将该字段按 ','拆分存放,然后循环CheckBoxList的值(循环之前已将CheckBoxList待选择的所有值绑定好了),在拆分存放中找到,则将其选中例如:/// &summary&
/// 字符串以“,”分组
/// &/summary&
/// &param name=&str&&&/param&
/// &returns&&/returns&
public Hashtable getStringGroup(string str)
string[] strings = str.Split(',');
Hashtable hs = new Hashtable();
for (int i = 0; i & strings.L i++)
hs.Add(strings[i].ToString(), strings[i].ToString());
/// &summary&
/// 设置选择了的角色
/// &/summary&
/// &param name=&al&&&/param&
protected void SetCheckRole(string roidStr)
Hashtable hs = this.getStringGroup(roidStr);
for (int i = 0; i & chklsRoleList.Items.C i++)
if (hs.ContainsKey(chklsRoleList.Items[i].Value))
chklsRoleList.Items[i].Selected =
}说道这了,不知道你明白了没?
提问者评价
其他类似问题
按默认排序
其他2条回答
不要用CheckBoxList,只能按行绑定用FormView,对bit数据类型的字段,自动显示为CheckBox*************************************补充:
建立好每列都是bit型的一个数据表,将FormView绑定到它,就可以了,不用写语句。
foreach(){//每箱如果数据库有就绑定}
checkboxlist的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁

我要回帖

更多关于 hashmap和hashtable 的文章

 

随机推荐