java怎么关闭扫描_Java - 关闭扫描程序和资源泄漏

不要将所有扫描仪命名为相同。如果您有多个这样的事情:

import java.util.Random;

import java.util.Scanner;

public class DayThree {

public static void main(String[] args) {

**Scanner textScanner = new Scanner(System.in);**

// boolean operands

// String(or objects) .equals() "this".equals("that") false

// primitive data types == 'a'=='a' -> true 5==6 false

// != 'a'!='a' -> false 5!=6 true

// ! !(true) -> false !(false) true

// > 5 > 4 -> true 'a' > 'b' false

// < 5 < 4 -> false

// <=

// >=

// && -> and 5 < 6 && 7 > 10 -> false

// if either side of and is false the outcome is false

// || -> or 5 < 6 || 7 > 10 -> true

// if either side of or is true the outcome is true

//System.out.println(!(5 < 10) && (7>3) || (true && false || true));

/*

System.out.println("What is the most amazing show on tv this week? ");

String show = textScanner.nextLine().toLowerCase(); //this is case sensitive

show = show.toLowerCase(); // changes the strng to a lowercase version

show = show.toUpperCase();

if(show.equalsIgnoreCase("game of thrones")){ // .equalsIgnoreCase( ignores caps/lower)

System.out.println("Yes it is!");

}

else{

System.out.println("You are wrong.");

System.out.println(show + " is clearly inferior to Game of Thrones.");

}

System.out.println("Who is your favorite character in " + show + ".");

String character = textScanner.nextLine().toLowerCase();

if(character.contains("dragon")){

System.out.println("CGI magic is so cool!");

}

else if(character.contains("lanister")){

System.out.println("Wrong house.");

}

else{

System.out.println(character + "is pretty cool I guess...");

}

*/

// asdf alternate multi line comment use ctrl + / on highlighted text.

// doing this a second time undoes the comment

// sdaf

// asdf

// asdf

// asdf

// 1. ask about favorite something (pet)

// 2. save that into a string all lowercase

// 3. have a series of if else (x3) and else statements about the something

//NOTE: DO NOT END CONDITIONALS WITH ; example: if(boolean); IS WRONG.

**Scanner numScanner = new Scanner(System.in);** // the variable tells you what to use it for

Random rand = new Random(); // this makes a new random object

System.out.println("Pick a number.");

int num = numScanner.nextInt();

int sNum = rand.nextInt(9) + 1; // gives me a random num between 1-10

// nextInt(bound)gives you a num from 0-bound

//adding one gives you a num from 1 - bound + 1

if(num > sNum){

System.out.println("Too high");

System.out.println("The number was " + sNum);

}

else if(num < sNum){

System.out.println("Too low");

System.out.println("The number was " + sNum);

}

else{

System.out.println("Wow are you psychic? ");

}

textScanner.close();

numScanner.close();

}//main method

}

为每个扫描仪放置*scanner name goes here*.close();。如果它们都具有相同的名称,则更改那些与其他扫描仪不同的内容。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值