佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1296|回复: 13

Java 救救我啊~~~大家帮忙一下

[复制链接]
发表于 22-2-2009 03:33 PM | 显示全部楼层 |阅读模式
有个问题是这样的:1.   Writea program that ask the user how ,many lines to print, how many stars to printeach line:Line?3Starsper line?13***************************************我做到的只是前面的,可是当我要从user的input那里在show出来要用什么code呢?import java.io.*;class ques3{ public static void main(String [ ]args)throws IOException {  BufferedReader stdin= new BufferedReader(new InputStreamReader(System.in));    String inData;  int num,y;  System.out.println("How many line you like to print?");  inData=stdin.readLine();  num=Integer.parseInt( inData);    System.out.println("How many star you like to print?");  inData=stdin.readLine();  y=Integer.parseInt(inData);      }}有谁知道呢?游

[ 本帖最后由 科技小女孩 于 13-4-2009 10:44 AM 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

发表于 22-2-2009 04:10 PM | 显示全部楼层
import java.io.*;
class ques3
{
public static void main(String [ ]args)throws IOException
{
  BufferedReader stdin= new BufferedReader(new InputStreamReader(System.in));
  
  String inData1,inData2;
  int num,y,i,j;

  System.out.println("How many line you like to print?");
  inData1=stdin.readLine();
  num=Integer.parseInt( inData1);
  
  System.out.println("How many star you like to print?");
  inData2=stdin.readLine();
  y=Integer.parseInt(inData2);

  for(i=0;i<num;i++){
        for(j=0;j<y;j++){
                System.out.print('*');}
        System.out.println();
}

  
   }
}

献丑了,我只会写小program
回复

使用道具 举报

 楼主| 发表于 22-2-2009 04:23 PM | 显示全部楼层
原帖由 basic 于 22-2-2009 04:10 PM 发表 import java.io.*;class ques3{ public static void main(String [ ]args)throws IOException {  BufferedReader stdin= new BufferedReader(new InputStreamReader(System.in));    String inData1,i ...

哦,原来是这样子
我一直想都想不到,谢谢你basic哦
回复

使用道具 举报

 楼主| 发表于 28-2-2009 12:34 PM | 显示全部楼层
再来一个关于array的
question: write a program to accept 10 numbers and store into an array then find the average of the 10 numbers.

import java.io.*;
class ques2{
public static void main(String args[ ])throws IOException{
BufferedReader stdin= new BufferedReader(new InputStreamReader(System.in));
String inputData1;
int ten_number[ ]=new int[11];
int total[ ]=new int[2];

for(int x=0;x<11;x++)
{
System.out.print("Please enter 10 number that you like:");
inputData1=stdin.readLine();
ten_number[x]=Integer.parseInt(inputData1);


}
System.out.print("Average of 10 number:"+(ten_number[x]/10));
}
}
接下去要怎样?
回复

使用道具 举报

发表于 28-2-2009 06:01 PM | 显示全部楼层
import java.util.Scanner;
class ques2{
public static void main(String args[ ]){
Scanner input = new Scanner(System.in);
int ten_number[ ]=new int[10];
int total=0;

for(int x=0;x<10;x++)
{
System.out.print("lease enter 10 number that you like:";

ten_number[x]=input.nextInt();
total+=ten_number[x];

}
System.out.print("Average of 10 number:"+(total/10));
}
}

不好意思,我又來Kepo了
用Scanner蛮方便的,不用parse 来 parse 去,
Array如果是10个的话,就从0-9,
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html
可以参考这个网页,还有nextLine, nextDouble之类的,
我是新手,所以只会写小program
在哪里念书?

[ 本帖最后由 basic 于 28-2-2009 06:02 PM 编辑 ]
回复

使用道具 举报

 楼主| 发表于 28-2-2009 06:19 PM | 显示全部楼层
原帖由 basic 于 28-2-2009 06:01 PM 发表 import java.util.Scanner;class ques2{public static void main(String args[ ]){Scanner input = new Scanner(System.in);int ten_number[ ]=new int[10];int total=0;for(int x=0;x
不过这个我没有学过哦
我在北海的工艺学院读
你呢?
回复

使用道具 举报

Follow Us
发表于 28-2-2009 10:47 PM | 显示全部楼层
我是在新纪元就读,我毕业了

现在在做工。

读IT常常要用Google,老师教不了这么多

IT永远学不完。。。。
回复

使用道具 举报

 楼主| 发表于 1-3-2009 10:30 AM | 显示全部楼层
原帖由 basic 于 28-2-2009 10:47 PM 发表 我是在新纪元就读,我毕业了现在在做工。读IT常常要用Google,老师教不了这么多 IT永远学不完。。。。
哦,不过我们老师教的应该是基本的吧!
可是他没教的东西能放进去吗?
我不懂老师哦, 没关系我会试试看放进去吧!
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 13-4-2009 10:43 AM | 显示全部楼层
hello
我又来了
我又有问题了
想问哦
i would like to create a program that will receive a string from the keyboard and count the number of vowels in the string. now the problem is i use this string s.indexOf() but still can't get

有谁可以帮我吗?
回复

使用道具 举报

发表于 13-4-2009 09:30 PM | 显示全部楼层
用 .length() 就可以 了 。。。
回复

使用道具 举报

发表于 13-4-2009 09:36 PM | 显示全部楼层
String a = "abcde";
                int c = 0 ;
                for (int b = 0 ; b < a.length() ; b++) {
                        if (a.charAt(b) == 'a' || a.charAt(b) == 'e') {
                                c++;
                        }
                }
回复

使用道具 举报

 楼主| 发表于 15-4-2009 07:23 PM | 显示全部楼层
原帖由 兔仙人 于 13-4-2009 09:36 PM 发表 String a = "abcde";                int c = 0 ;                for (int b = 0 ; b < a.length() ; b++) {                        if (a.charAt(b) == 'a' || a.charAt(b) == 'e') {                                c++;                        }                }
我做到了,可是怎样把全部的vowel算起来呢?
我的code;

import java.io.*;

class countvowel
{

static DataInputStream s=new DataInputStream(System.in);

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

{

String anyvowel;



System.out.println("Enter a string: ");

anyvowel=s.readLine();

System.out.println("String: "+anyvowel);

System.out.println();

int c = 0 ;
        for (int b = 0 ; b < anyvowel.length() ; b++) {
        if (anyvowel.charAt(b) == 'a' || anyvowel.charAt(b) == 'e'||anyvowel.charAt(b)=='i'||anyvowel.charAt(b)=='o'||anyvowel.charAt(b)=='u') {
        c++;
        System.out.println("The vowel that have in the string:"+ anyvowel.charAt(b));

        }
        }





}
}

[ 本帖最后由 科技小女孩 于 15-4-2009 09:14 PM 编辑 ]
回复

使用道具 举报

发表于 15-4-2009 09:38 PM | 显示全部楼层

回复 12# 科技小女孩 的帖子

System.out.println("The vowel that have in the string:"+ anyvowel.charAt(b));
}
}
下面加
System.out.println("The total number of vowel in the string:" + c );
回复

使用道具 举报

 楼主| 发表于 16-4-2009 08:20 AM | 显示全部楼层
原帖由 wuichia 于 15-4-2009 09:38 PM 发表 System.out.println("The vowel that have in the string:"+ anyvowel.charAt(b));}}下面加System.out.println("The total number of vowel in the string:" + c );
谢谢你,我做到了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 14-12-2025 09:41 AM , Processed in 0.139474 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表