Eclipse导出错误中的Java编程 套餐票簿; 导入java.util.*; 公营课{ 公共静态void main(字符串参数[]){ **Scanner in=新扫描仪(System.in)**;“资源泄漏:'in'从未关闭” int ch,i,n,movch;String rowch[]=新字符串[12]; int colch[]=新int[12]; 字符串时间=新字符串(); 字符串时间检查=新字符串(); show objshow=new show(); 屏幕对象屏幕=新屏幕(); 票证对象=新票证(); while(true){ System.out.println(“\n\t\t电影票预订系统\n”); System.out.println(“1.预订电影票”); System.out.println(“2.See Movies/Show times”); System.out.println(“3.Exit”); System.out.println(“\n高级预订现在已关闭。”); System.out.println(“\n输入选项”); ch=in.nextInt(); 开关(ch) { 案例1:objshow.display_show_timings(); System.out.println(“选择电影”); movch=in.nextInt(); 做{ System.out.println(“输入显示时间(hh:mm)”; 时间=in.next(); timecheck=objshow.check_time(movch,time); }while(timecheck.equals(“false”)); System.out.println(“输入座位数”); n=in.nextInt(); 对于(i=0;i
您希望使用Eclipse导出错误中的Java编程 套餐票簿; 导入java.util.*; 公营课{ 公共静态void main(字符串参数[]){ **Scanner in=新扫描仪(System.in)**;“资源泄漏:'in'从未关闭” int ch,i,n,movch;String rowch[]=新字符串[12]; int colch[]=新int[12]; 字符串时间=新字符串(); 字符串时间检查=新字符串(); show objshow=new show(); 屏幕对象屏幕=新屏幕(); 票证对象=新票证(); while(true){ System.out.println(“\n\t\t电影票预订系统\n”); System.out.println(“1.预订电影票”); System.out.println(“2.See Movies/Show times”); System.out.println(“3.Exit”); System.out.println(“\n高级预订现在已关闭。”); System.out.println(“\n输入选项”); ch=in.nextInt(); 开关(ch) { 案例1:objshow.display_show_timings(); System.out.println(“选择电影”); movch=in.nextInt(); 做{ System.out.println(“输入显示时间(hh:mm)”; 时间=in.next(); timecheck=objshow.check_time(movch,time); }while(timecheck.equals(“false”)); System.out.println(“输入座位数”); n=in.nextInt(); 对于(i=0;i,java,eclipse,jar,Java,Eclipse,Jar,您希望使用try with resources,它将在尝试结束时自动关闭流 package ticketBook; import java.util.*; public class run { public static void main(String args[]){ **Scanner in = new Scanner(System.in)**; "Resource leak: 'in' is never closed" int ch,i,n,
try with resources
,它将在尝试结束时自动关闭流
package ticketBook;
import java.util.*;
public class run {
public static void main(String args[]){
**Scanner in = new Scanner(System.in)**; "Resource leak: 'in' is never closed"
int ch,i,n,movch; String rowch[]=new String[12];
int colch[]=new int[12];
String time = new String();
String timecheck = new String();
show objshow = new show();
screen objscreen = new screen();
ticket objticket = new ticket();
while(true){
System.out.println("\n\t\t Movie Ticket Booking System\n");
System.out.println("1.Book Movie Tickets");
System.out.println("2.See Movies/Show Timings");
System.out.println("3.Exit");
System.out.println("\nAdvanced Bookings are closed as of now.");
System.out.println("\nEnter Choice");
ch = in.nextInt();
switch(ch)
{
case 1: objshow.display_show_timings();
System.out.println("Choose the Movie");
movch=in.nextInt();
do{
System.out.println("Enter Show timings (hh:mm)");
time=in.next();
timecheck=objshow.check_time(movch,time);
}while(timecheck.equals("false"));
System.out.println("Enter Number of seats");
n=in.nextInt();
for(i=0;i<n;i++){
objscreen.display_seats();
rowch[i]=in.next().toUpperCase();
objshow.show_empty_seats(rowch[i],movch);
colch[i]=in.nextInt();
if(objshow.check_seats(rowch[i],colch[i],movch))
{
System.out.println("Seat is not available");
}
objshow.fill_seat(rowch[i],colch[i],movch);
}
for(i=0;i<n;i++)
{
objticket.print_ticket(objshow.getmovie(movch), time, 3, objscreen.getcat(rowch[i]), rowch[i], colch[i]);
}
break;
case 2: objshow.display_show_timings();
break;
case 3: System.exit(0);
}
}
}
}
如果您正在使用JDK6或之前的版本:
public static void main(String args[]){
try(Scanner in = new Scanner(System.in)) {
// rest of the code.
} catch (Exception e){
e.printStackTrace();
}
}
我想这不是一个错误,只是一个警告。
public static void main(String args[]){
Scanner in = new Scanner(System.in);
try {
// rest of the code.
} catch (Exception e){
e.printStackTrace();
} finally {
in.close();
}
}