20220216 º¹½À
p166 Çâ»óµÈ for¹®, FileInputStream, ·¹°í°ü¸®½Ã½ºÅÛ
import java.io.*; //ÀξƿôDz °¡Á®¿À±â
class LegoFile//Lego °ü¸® ½Ã½ºÅÛ
{
/*
¸ðµ¨¹øÈ£:
¸ðµ¨¸í:
¿¬µµ:
Á¦Á¶»ç:
°¡°Ý:
¿¬·É:
Á¶¸³¼³¸í¼ À¯¹«:
int m_Num; // Ŭ·¡½º·Î ¸¸µé ¶§¿¡´Â ÀÌ·± ½ÄÀ¸·Î ¸É¹öº¯¼ö !!!
String m_Name;
int m_year;
etc..
*/
static void print(String[][] lego)
{
//ÀÌÁß for ¶Ç´Â Çâ»êµÈ for
for (int i=0;i<lego.length ;i++ )
{
for (int j=0;j<lego[i].length ;j++ )
{
System.out.printf("[ %s ]",lego[i][j]);
}
System.out.println();
}
}
static int total_price(String[][] lego)
{
int total=0;;
int cnt=0;
//p166 Çâ»óµÈ for¹®
for (String[] lg : lego)
{
total+=Integer.parseInt(lg[4]);
cnt++;
}
System.out.println("ÃÑ ·¹°í °³¼ö: "+cnt);
return total;
}
static int year(String[][] lego, int chk_year)
{
System.out.println("<"+chk_year+"¿¡ »ý»êµÈ Á¦Ç°>");
int cnt=0;
for (String[] lg : lego)
{
if (Integer.parseInt(lg[2])==chk_year)
{
cnt++;
System.out.printf("[%s]",lg[0]);
}
}
System.out.println();
return cnt;
}
public static void main(String[] args) throws IOException
{
/*
¸ðµ¨¹øÈ£:
¸ðµ¨¸í:
¿¬µµ:
Á¦Á¶»ç:
°¡°Ý:
¿¬·É:
Á¶¸³¼³¸í¼ À¯¹«:
//¹è¿Àº º¯¼ö (¾ðÁ¦µçÁö »èÁ¦µÈ´Ù.)
//scanner (ÀúÀå X ¹è¿(Ŭ·¡½º), ÆÄÀÏ, DB)
//ÀÔÃâ·Â : Å°º¸µå·Î ÀÔ·Â, ¸ð´ÏÅÍ·Î Ãâ·Â
//½ºÆ®¸²À̶õ µ¥ÀÌÅ͸¦ ¿î¹ÝÇϴµ¥¿¡ »ç¿ëµÇ´Â ¿¬°áÅë·Î!! (³×Æ®¿öÅ©¿¡¼´Â ÆÐŶÀ̶ó ºÎ¸§)
*/
FileInputStream fis = new FileInputStream(args[0]); //°´Ã¼ »ý¼º
int data=0;
while ((data=fis.read()) != -1) // -1ÀÌ ÆÄÀÏÀÇ ³¡À» ÀǹÌÇÔ (ÆÄÀÏÀÇ ³¡À» Àбâ Àü±îÁö ½ÇÇàÇ϶ó)
{
char c = (char)data;
System.out.println(c);
}
String[][] lego = new String[][] {
{"70310","³ªÀÌÆ° ¿Õ±¹ÀÇ ¹èƲ º¼·¡½ºÅÍ","2016","·¹ÄÚÄÚ¸®¾Æ","30000","10","Y"},
{"70911","Æë±Ï¸ÇÀÇ ¾Æƽ ·Ñ·¯","2017","·¹ÄÚÄÚ¸®¾Æ","10000","10","Y"},
{"75976","·¹Å·º¼","2013","·¹ÄÚÄÚ¸®¾Æ","20000","10","Y"},
{"71737","´ÑÀÚÂ÷Àú","2021","·¹ÄÚÄÚ¸®¾Æ","35000","10","Y"},
{"72123","McLaren Senna GTR","2019","·¹ÄÚÄÚ¸®¾Æ","33000","10","Y"},
{"71738","ÀòÀÇ Å¸ÀÌź ·Îº¿ ÀüÅõ","2020","·¹ÄÚÄÚ¸®¾Æ","40000","10","Y"},
{"42122","Jeep Wrangler","2021","·¹ÄÚÄÚ¸®¾Æ","20000","10","Y"},
{"70317","asd","2022","·¹ÄÚÄÚ¸®¾Æ","28000","10","Y"},
{"70318","asd","2028","·¹ÄÚÄÚ¸®¾Æ","50000","10","Y"},
{"70319","asd","2028","·¹ÄÚÄÚ¸®¾Æ","50000","10","Y"}
};
System.out.println("·¹°í°ü¸®½Ã½ºÅÛ");
print(lego);
System.out.println("-----------------------------------------------");
int price = total_price(lego);
System.out.println("ÃÑ °¡°Ý: "+price);
System.out.println("-----------------------------------------------");
System.out.println("ÃÑ °³¼ö: "+year(lego,2017));
System.out.println("ÃÑ °³¼ö: "+year(lego,2018));
System.out.println("ÃÑ °³¼ö: "+year(lego,2019));
System.out.println("ÃÑ °³¼ö: "+year(lego,2020));
}
}
main(String[] args)
class T0216_39 //¸ÞÀÎ ÇÔ¼öÀÇ String[] args ¹è¿¿¡ ´ëÇØ ¾Ë¾Æº¸ÀÚ
{
public static void main(String[] args)
{
// cmd : java T0216_39 h 1.txt 2.txt
String[] a =new String[]{"1","2"};
System.out.println("a¹è¿ÀÇ °ª: "+a[0]);
System.out.println("args¹è¿ÀÇ °ª: "+args[0]);
System.out.println("args¹è¿ÀÇ °ª: "+args[1]);
System.out.println("args¹è¿ÀÇ °ª: "+args[2]);
if (args[0].equals("h"))
{
System.out.println("µµ¿ò¸»");
}
}
}