2013-12-16 3 views
0

안녕하십니까. 저는 Java에 익숙하지 않습니다. 선생님이 우리에게 준이 과제에 도움이 필요합니다. 여기 내 프로그램이 있습니다 ... 목표는 매번 내가 선택한 과정과 출력 시간을 선택하는 것입니다. 1, 내가 명확하게 설명하지 못할 경우 매번 사용자가 미안 .... 코스 나 출력이 채워 일정을 선택 내 영어 나쁜 .....2D 배열 사용자 입력

import java.io.*; 
public class Array2D_input { 

public static void main(String[] args)throws IOException { 
BufferedReader in= new BufferedReader(new InputStreamReader(System.in)); 
int X=0; 
int num=0; 
String [] subject={" ","C#Programming","Autocad","Robotics","JavaProgramming"}; 
String [] time={" ","8:00 - 12:00","12:00 - 4:00","4:00 - 8:00"}; 

    int [][] N=new int[5][4]; 
do{ 
    System.out.println("SUBJECT ENROLLMENT\n"); 
    System.out.println("Subjects Offered"); 

    for(int s=1;s<=4;s++) 
    { 
     System.out.print(" "+s+" - "+subject[s]); 
     System.out.println(); 
    } 
     System.out.println(); 
     System.out.print("YOUR CHOICE : "); 
     int a=Integer.parseInt(in.readLine()); 
     N[4][a]++; 
    for(int t=1;t<=3;t++) 
    { 
     System.out.print(" "+t+" - "+time[t]); 
     System.out.println(); 
    } 
     System.out.print("TIME SCHEDULE : "); 
     int tm=Integer.parseInt(in.readLine()); 

     num=num+1; 



     System.out.print("More Entries <Y/N> : "); 
     X=in.readLine().charAt(0); 

    }  
    while(X=='Y');  


    //System.out.print("\n\tENROLLMENT SUMMARY\n"); 
    System.out.print("\t\t   TIME SCHEDULE\n"); 
    System.out.print("SUBJECTS\t 8:00-12:00\t 12:00-4:00\t  4:00-8:00\t total"); 

    for(int s=0; s<5; s++) 
    { 
     System.out.print(""+subject[s]); 
     System.out.println(); 
     for(int t=0; t<4; t++) 
      System.out.print("\t\t\t "+N[s][t]); 
      System.out.println(); 

    } 

} 

}

다음
+1

문제 또는 어려움 당신은 코드와 데를 설명해주십시오. 예상되는 결과는 무엇입니까? –

+0

출력은 다음과 같아야합니다. [link] (http://i710.photobucket.com/albums/ww101/inverse222/zxczxczxczxczxc_zps71399447.jpg) – user3107526

답변

0

은이다 귀하의 작업에 대한 개정 된 코드, 희망이 당신을 도울 것입니다.

import java.io.*; 

public class Array2D_input { 

    public static void main(String[] args) throws IOException { 
     BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); 
     String x = ""; 
     String[] subject = { "C#Programming", "Autocad", "Robotics", "JavaProgramming" }; 
     String[] time = { "8:00 - 12:00", "12:00 - 4:00", "4:00 - 8:00" }; 
     int[][] N = new int[subject.length][time.length]; 
     // Initializing array with default values 
     for (int i = 0; i < subject.length; i++) { 
      for (int j = 0; j < time.length; j++) { 
       N[i][j] = 0; 
      } 
     } 
     do { 
      System.out.println("SUBJECT ENROLLMENT\n"); 
      System.out.println("Subjects Offered"); 

      for (int s = 0; s < subject.length; s++) { 
       System.out.print(" " + (s + 1) + " - " + subject[s]); 
       System.out.println(); 
      } 
      System.out.println(); 
      System.out.print("YOUR CHOICE : "); 
      int a = readNumber(in, subject.length); 
      for (int t = 0; t < time.length; t++) { 
       System.out.print(" " + (t + 1) + " - " + time[t]); 
       System.out.println(); 
      } 
      System.out.print("TIME SCHEDULE : "); 
      int tm = readNumber(in, time.length); 
      N[a - 1][tm - 1]++; 

      System.out.print("More Entries <Y/N> : "); 
      x = in.readLine(); 

     } while (x.equalsIgnoreCase("Y")); 

     // System.out.print("\n\tENROLLMENT SUMMARY\n"); 
     System.out.print("\t\t   TIME SCHEDULE\n"); 
     System.out.print("SUBJECTS\t 8:00-12:00\t 12:00-4:00\t  4:00-8:00\t Total"); 

     for (int s = 0; s < subject.length; s++) { 
      int count = 0; 
      System.out.println(); 
      System.out.println(subject[s]); 
      for (int t = 0; t < time.length; t++) { 
       System.out.print("\t\t " + N[s][t]); 
       count += N[s][t]; 
      } 
      System.out.print("\t\t " + count); 
     } 

    } 

    /** 
    * Function to read input from the console and also check for max value 
    * 
    * @param in 
    * @param maxLimit 
    * @return 
    * @throws IOException 
    */ 
    public static int readNumber(BufferedReader in, int maxLimit) throws IOException { 
     int choice = 0; 
     try { 
      choice = Integer.parseInt(in.readLine()); 
     } catch (NumberFormatException nf) { 
      System.out.println("Enter integer only:"); 
      choice = readNumber(in, maxLimit); 
     } 
     if (choice > maxLimit) { 
      System.out.println("Enter only given options"); 
      choice = readNumber(in, maxLimit); 
     } 
     return choice; 
    } 
} 
+0

waw! 덕분에 당신은 정말로 나를 도왔습니다 ... 다시 한번 감사드립니다! – user3107526

+0

내 기쁨 .. .. :) –

0

자바 2 차원 배열 입력 예 :

//Coded BY Anurag Goel 
//Basic 2DArray Program 
import java.util.Scanner; 
public class array2d { 
public static void main(String args []) 
{ 
int [][] arr =new int[5][5]; 
System.out.println("Enter student roll no and their subject codes"); 
Scanner o = new Scanner(System.in); 
for(int i=0;i<5;i++) 
{ 
System.out.println("Enter "+(i+1)+"th student subject codes "); 
for(int k=0;k<5;k++) 
{ 
System.out.println("Enter "+(k+1)+"th subject code : "); 
arr[i][k]=o.nextInt(); 
} 
} 
for(int j=0;j<5;j++) 
{ 
System.out.print(""+(j+1)+"th student subject codes "); 
for(int l=0;l<5;l++) 
{ 
System.out.print(" "+arr[j][l]+" "); 
} 
System.out.println(""); 

} 

} 
}