• 締切済み

誰か教えてください!

javaのプログラムですが import java.io.*; import java.util.*; public class Suudoku{ Suudoku(int[] data){ public static void main(String[] args);{ int[] data = new int[81]; if(args.length!=1){ System.err.println("need 1 argument"); System.exit(1); } BufferedReader br; try{ br = new BufferedReader(new FileReader(args[0])); for(int i=0;i<9;i++){ String tmp = br.readLine(); StringTokenizer stn = new StringTokenizer(tmp," ",false); for(int j=0;j<9;j++){ data[i*9+j]=Integer.parseInt(stn.nextToken()); } } }catch(Exception e){ System.err.println(""+e); System.exit(1); } new Suudoku(data); int board[][] = {{ 6, 0, 1, 0, 7, 0, 2, 0, 8 }, { 0, 7, 0, 6, 0, 8, 0, 9, 0 }, { 9, 0, 0, 0, 3, 0, 0, 0, 7 }, { 0, 8, 0, 3, 0, 4, 0, 1, 0 }, { 4, 0, 2, 0, 0, 0, 9, 0, 5 }, { 0, 6, 0, 1, 0, 9, 0, 2, 0 }, { 1, 0, 0, 0, 8, 0, 0, 0, 2 }, { 0, 2, 0, 7, 0, 6, 0, 5, 0 }, { 3, 0, 7, 0, 9, 0, 6, 0, 1 }}; } } } の後はどうようにしたら良いか教えて下さい。

  • Java
  • 回答数1
  • ありがとう数0

みんなの回答

  • yukimican
  • ベストアンサー率70% (112/159)
回答No.1

コメントが無いソースコードだけを見せられてもわかりません。 まず、これが何をするプログラムで、何をしたいのかを書きましょう。

関連するQ&A

  • 入力された入力値と最大値、最小値を表示させるプログラムで、最大値と最小

    入力された入力値と最大値、最小値を表示させるプログラムで、最大値と最小値のプログラムを下記に作成してみたら最小値が0になりました。そして、もう一つ繰り返し文を作ってみたら、最大値・最小値がうまく表示されました。この違いはどうしてですか?教えてください。 import java.io.*; class Hairetu1 { public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("データはいくつですか?"); String str = br.readLine(); int num = Integer.parseInt(str); int a[]=new int[num]; int i; int max=0; int min=a[0]; for(i=0; i<a.length; i++){ System.out.print((i+1)+"番目は?"); str = br.readLine(); int tmp = Integer.parseInt(str); a[i] = tmp; if(max<tmp){ max=tmp; } if(min>tmp){ min=tmp; } } System.out.println("入力した値は"+test.length); System.out.println("最大は"+max); System.out.println("最小は"+min); } }

    • ベストアンサー
    • Java
  • 九九を横に表示する。

    入力した整数までの九九を 1 2 3 4 5 6 7 8 9 2 4 6 8 10 12 14 16 18 以下略 のように表示したいのですが 私の作ったプログラムだと縦に表示されてしまいます。 1 2 3 4 5 6 7 8 9 のように。(-"-;A ... プログラムは以下の通りです。 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class q07quiz07 { /** * @param args */ public static void main(String[] args)throws IOException { // TODO 自動生成されたメソッド・スタブ System.out.println("整数を入力してください。"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = br.readLine(); int num = Integer.parseInt(str); int i , j; i = 1; while(i <= num){ j = 1; while(j <= 9){ System.out.println(i*j+ " "); j++; } System.out.println(); i++; } } } 回答よろしくお願いします。

    • ベストアンサー
    • Java
  • vectorを使った列の計算について

    への補足 列合計を計算したいのですが、 まったくといってどうすればいいのか思いつきません>< どのようにループすれば列合計を計算、出力できるのでしょうか? import java.util.*; import java.io.*; public class Gyosyukei { public static void main(String args[]) { try{ BufferedReader br = new BufferedReader(new FileReader(args[0])); String str; while((str = br.readLine()) != null){ // 1行を格納するVector Vector vcLine = new Vector(); StringTokenizer st = new StringTokenizer(str,","); for(int i =0;st.hasMoreTokens(); i++){ String token = st.nextToken(); // 行の要素に追加 vcLine.addElement(token); } /* 行合計 */ int gyosum = 0; int num = 0; for(int j =1; j < vcLine.size(); j++){ num = Integer.parseInt((String)vcLine.get(j)); gyosum += num; } System.out.println(gyosum); } } catch(IOException e){ } catch(ArrayIndexOutOfBoundsException ae){ } } }

    • ベストアンサー
    • Java
  • javaプログラミングの質問です。

    http://questionbox.jp.msn.com/qa1030602.html?StatusCheck=ON に載っている、プログラムを以下のようにQuestionというクラスで実行してみたところ、 import java.io.*; class Question{ public static void main(String Args[]){ BufferedReader reader = null; String strArray[][] = new String[4][4]; String fileName = "foo.txt"; int i = 0; int j = 0; try{ reader = new BufferedReader ( new FileReader(fileName) ); String line; while ( (line = reader.readLine() ) != null ){ StringTokenizer st = new StringTokenizer ( line ); while ( st.hasMoreTokens() ){ strArray[i][j] = st.nextToken(); System.out.print ( strArray[i][j] + " " ); j ++; } j = 0; i ++; System.out.println (""); } } catch ( Exception e ){ System.out.println ( e.toString() ); } } } Exception in thread "main" java.lang.Error: コンパイル問題が未解決です。 StringTokenizer を型に解決できません。 StringTokenizer を型に解決できません。 というエラーが出ます。 このサイトの質問者はうまくいっているようなのですが、私のコンパイラがうまく動いていないのでしょうか? java version "1.6.0_07" を使っていて、Eclipseを用いてコンパイルをしたりしています。 どなたかご指摘をどうぞよろしくお願いいたします。

    • ベストアンサー
    • Java
  • 配列で最大・最小値を求める

    import java.io.*; class Prog10_2 { public static void main(String args[])throws IOException { System.out.println("10個の整数を入力してください。"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int num[] = new int[10]; for(int i=0; i<num.length; i++){ String str = br.readLine(); int tmp = Integer.parseInt(str); num[i] = tmp; } int max = 0; int min = 0; for(int i=0; i<num.length; i++){ if(max < num[i]){ max = num[i]; } if(min > num[i]){ min = num[i]; } } System.out.println("最大値は"+max+"で、最小値は"+min+"です。"); } }   というコマンドを実行すると、最大値はちゃんと表示されるのですが、 最小値はいつも"0"しか表示されません。どこを修正すればいいのでしょうか? どなたか分かる方いらっしゃいましたら、よろしくお願いします。

    • ベストアンサー
    • Java
  • 今勉強中のjavaで。わからないことがあります。

    import java.io.*; class Ireru { public static void main(String args[]) throws IOException{ System.out.println("あなたは何歳ですか?"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str1 = br.readLine(); int num =Integer.parseInt(str1); System.out.println("あなたは" + num +"歳です。"); } } ------------------------------- import java.io.*; class Ireru { public static void main(String args[]) throws IOException{ System.out.println("あなたは何歳ですか?"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str1 = br.readLine(); System.out.println("あなたは" + str1 +"歳です。"); } } なぜ下では悪いのですか?なぜnum をつかないといけないかがわかりません。正確には str1とnumの違いがわからなくて困っています。何が混乱の原因ですか?

    • ベストアンサー
    • Java
  • プログラムの組み合わせ方

    java初心者です。 2つのプログラムを組み合わせて1つのプログラムにしたいんですが、イマイチ分かりません。 このプログラムと、 import java.io.*; class Hello2 {  public static void main(String[] args) throws IOException {   System.out.println("名前を入力してください");   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));   String str = br.readLine();   System.out.println(str + "さん、こんにちは!");  } } このプログラムを、 import java.io.*; class Sanbai{  public static void main(String[] args) throws IOException {   System.out.println("好きな数を入力してください");   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));   String str = br.readLine();   int x;   x = Integer.parseInt(str);   System.out.println("あなたの入力した数:" + x);   System.out.println("その3倍の数:" + (x*3));  } } 組み合わせて1つのプログラムにするにはどうしたらいいですか?(>_<)

    • ベストアンサー
    • Java
  • CSV読み込み 文字化け

    失礼いたします。 以前のログを見てエンコードを設定してみたのですが、出力が文字化けします。ローカルファイルを読み込んでコンソール出力しているだけなのですが・・・。 分かる方、よろしくお願いします。 -------------------ソースはここから import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; // import java.io.FileReader; FileReaderからInputStreamReaderに変更済み import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class ReadCSV { public static void main(String[] args) { try { File csv = new File("C:\\AP.csv"); // BufferedReader br = new BufferedReader(new FileReader(csv)); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(csv),"EUC_JP")); // BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(csv),"MS932")); while (br.ready()) { String line = br.readLine(); StringTokenizer st = new StringTokenizer(line, ","); while (st.hasMoreTokens()) { System.out.print(st.nextToken() + "\t"); } System.out.println(); } br.close(); } catch (FileNotFoundException e) { キャッチ処理 }

    • ベストアンサー
    • Java
  • 配列の値の参照について

    下記のプログラムの-------------で囲まれた部分が、コンパイルは通るのですが実行すると"value[1][0]"以降が参照できません(ここではcount=3 となっています)。 for文を使わずに"System.out.println(value[1][0])"とすると値を取り出せるのですが…。 実行時のエラーは Exception in thread "main" java.lang.ArrayIndexOutOfBoundException: 3 です。 ソースコードをそのまま載せて長文になってしまい申し訳ありません。 プログラム初心者なので、些細なことでもいいので回答お願いします。 import java.util.*; import java.io.*; public class Search { static String dataFileName = "CityData.txt"; ArrayList<String> array = new ArrayList<String>(); GetDataCount gdc = new GetDataCount(dataFileName); int count = gdc.getCount(); int count2 = 0; String[][] value = new String[count][3]; public Search(String dataFileName){ try{ BufferedReader reader = new BufferedReader( new FileReader(dataFileName) ); String line = ""; while((line = reader.readLine()) != null){ Vector<String> variable = readLine(line); System.out.println(variable); count2++; } }catch(IOException e){ System.out.println(e); } //---------------------------------------------------------- for (int i=0; i<count2; i++){ for (int j=0; i<3; j++){ System.out.println(value[i][j]); } } //---------------------------------------------------------- } public Vector<String> readLine( String line ){ StringTokenizer st = new StringTokenizer( line, "," ); Vector<String> variable = new Vector<String>(); for( int i=0 ; i<3 ; i++ ){ String data = st.nextToken(); variable.addElement( data ); value[count2][i] = data; System.out.println(value[count2][i]); } return variable; } public class GetDataCount{ int count = 0; public GetDataCount(String dataFileName){ try{ BufferedReader reader = new BufferedReader( new FileReader(dataFileName) ); String line = ""; while((line = reader.readLine()) != null){ count++; } }catch(IOException e){ System.out.println(e); } } public int getCount(){ return count; } } public static void main(String[] args){ new Search(dataFileName); } }

  • 実行速度を速くする方法

    javaで整数がランダムに記述されたテキストファイルを読み込み、ソートし、テキストファイルに出力させるプログラムを考えています。 テキストファイルからの読み込みはあらかじめ配列を作っておき、scannerで読み込んでいます。 アルゴリズム(バブルソート)を変更せずに実行速度を速くするにはテキストファイルの読み込みを速くしたいのですが、どのように変更すれば良いでしょうか。 ソート数としては10万くらいを考えています。 またプログラムの記述が変なところがあれば教えていただければありがたいです。 import java.io.*; import java.util.Scanner; class test1_4{ public static void main(String args[]){ long start = System.currentTimeMillis(); try{ File filein = new File("./input.txt"); BufferedReader br = new BufferedReader(new FileReader(filein)); int x[] = new int[100000]; br = new BufferedReader(new FileReader(filein)); Scanner scan = new Scanner(new File("./input.txt")); int k=0; while(scan.hasNext()){ x[k] = scan.nextInt(); k++; } br.close(); for(int i=0; i<k; i++){ for(int j=k; j>0; j--){ int z = j-1; if(x[z] > x[j]){ int tmp = x[j]; x[j] = x[z]; x[z] = tmp; } } } try{ File fileout = new File("./output.txt"); BufferedWriter bw = new BufferedWriter(new FileWriter(fileout)); PrintWriter pw = new PrintWriter(bw); for(int i=1; i<k+1; i++){ if(x[i]>0){ pw.print(x[i]); pw.print(" "); if (i%10 == 0) { pw.print("\r\n"); } } } pw.close(); bw.close(); } catch(IOException e){ System.out.println(e); } long stop = System.currentTimeMillis(); System.out.println("実行にかかった" + (stop - start) + " ミリ秒です"); } catch(FileNotFoundException e){ System.out.println(e); } catch(IOException e){ System.out.println(e); } } }

専門家に質問してみよう