| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 567 人关注过本帖
标题:再帮我解决一下!!谢谢!
只看楼主 加入收藏
项目经理
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2005-8-29
收藏
 问题点数:0 回复次数:5 
再帮我解决一下!!谢谢!
  用什么函数连续接收用户输入的5个数字,并能操纵这5个数字??
是readin()么?
eg: 请用户输入5~15之间的5个数字,并用横状图表示.
         5 2 7 10 3
  *****
  **
  *******
  **********
  ***

[此贴子已经被作者于2005-9-11 21:18:51编辑过]


搜索更多相关主题的帖子: 用户 
2005-09-11 09:21
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
// 程序运行时,数字是一个一个输入的
import
import
import

class Keyboard
{
  private static String getEingabe()
  {
    String eingabe;
    BufferedReader reader;
    reader = new BufferedReader( new InputStreamReader( System.in ) );
    try
    {
      eingabe = reader.readLine();
      return eingabe;
    }
    catch ( IOException e )
    {
      e.printStackTrace();
    }
    return null;
  }

  public static int getInteger()
  {
    String eingabe;
    do
    {
      eingabe = getEingabe();
    }while(checkIntegerInput(eingabe) == false);
   
    int zahl = Integer.parseInt( eingabe );
    return zahl;
  }

  public static double getDouble()
  {
    String eingabe = getEingabe();
    double zahl = Double.parseDouble( eingabe );
    return zahl;
  }

  public static String getString()
  {
    String eingabe = getEingabe();
    return eingabe;
  }

  public static boolean checkIntegerInput(String s)
  {
    char [] c = s.toCharArray();
    for(int i = 0; i<c.length; i++)
    {
      int d = (int)c[i];
      if(d<48 || d>57)
      {
        MyException e = newMyException("Invalid input, you should input all integer number");
        return false;
      }
    }
    return true;
  }
}

class MyException
{
  MyException(String s)
  {
    System.err.println(s);
    System.out.println("Please try enter a new number between 5 and 15,inclusive 5 and 15.");
  }
  public int tryAgain()
  {
    return Keyboard.getInteger();
  }
}
public class PrintAsterisk
{
  public PrintAsterisk()
  {
    int [] nums = new int[5];
    for(int i = 0; i<nums.length; i++)
    {
      System.out.println("Please input an integer number between 5 and 15, inclusive");
      nums[i] = Keyboard.getInteger();
      while(nums[i] > 15 || nums[i] < 5)
      {
        MyException e = new MyException("invalid input");
        nums[i] = e.tryAgain();
      }
    }
    for(int i = 0; i<nums.length; i++)
    {
      for(int j = 0; j<nums[i]; j++)
      {
        System.out.print("*");
      }
      System.out.println();
    }     
  }
  public static void main(String [] args)
  {
    PrintAsterisk pa = new PrintAsterisk();
  }
}

自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2005-09-11 19:17
项目经理
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2005-8-29
收藏
得分:0 
import *;
class xiti3
{
public static void main (String[] arg)
{
  int a[]=0;
  DataInputStream in = new DataInputStream(System.in);
  try
  {
   for(int i=0;i<5;i++)
   {
    System.out.print("请输入1~15之间的一个数字:");
    a[i]=Integer.parseInt(in.readLine());
   }
  while (int i>0)
  {
    int i=5;
    System.out.print("您输入了以下5个数字:");
    System.out.print(a[i]);
    i--;
   }
   for(int j=0;j<5;j++)
   {
    for(int k=1;k<=a[j];k++)
    System.out.print("*");}
       System.out.println("");
      }catch(Exception e){  
  
  }
}
}
这是我写的一个,不知道哪里错了,希望大家帮我看看!!

[此贴子已经被作者于2005-9-11 21:21:09编辑过]



偶现在还是一只小菜鸟,希望以后可以飞的更高~~
2005-09-11 20:31
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
// 如果不做严格要求的话,那么勉强可以通过
import *;

class xiti3
{
  public static void main (String[] arg)
  {
    int a[]=new int[5];   // here pay attention
    DataInputStream in = new DataInputStream(System.in);
    try
    {
      for(int i=0;i<5;i++)
      {
        System.out.print("请输入1~15之间的一个数字:");
        a[i]=Integer.parseInt(in.readLine());
      }
      System.out.print("您输入了以下5个数字:");
      int i =5;                                                          // and here this while loop pay attention
      while (i>0)
      {
        System.out.print(a[5-i] + " ");
        i--;
      }
      System.out.println();
      for(int j=0;j<5;j++)
      {
        for(int k=0;k<a[j];k++)
        {
          System.out.print("*");
        }
        System.out.println();
      }
    }
    catch(Exception e)
    {  
      System.err.println(e.toString());  
    }
  }
}

自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2005-09-11 21:41
jackych
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2005-8-23
收藏
得分:0 
HI! 帅哥一族 你的答案

import *;
class xiti3
{
public static void main (String[] arg)
{
  int a[]=new int[5];
  int b=5;
  DataInputStream in = new DataInputStream(System.in);
  try
  {
    for(int i=0;i<5;i++)
    {
     System.out.print("请输入1~15之间的一个数字:");
     a[i]=Integer.parseInt(in.readLine());
    }
   
    System.out.println("您输入了以下5个数字:");
   
     for (int i = 0; i<5; i++)
     {
      System.out.println (a[i]);
     }
  
      for(int j=0;j<5;j++)
      {
        
           for(int k=1;k<=a[j];k++)
           {
            System.out.print("*");
           }
         
         System.out.println("");
   }
        
    }
      catch(Exception e){ }
  
  
}
}

2005-09-11 22:32
项目经理
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2005-8-29
收藏
得分:0 
谢谢两位~~~~问题已解决!!!!!!!!!!

偶现在还是一只小菜鸟,希望以后可以飞的更高~~
2005-09-12 07:41
快速回复:再帮我解决一下!!谢谢!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012808 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved