Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package secondProblemlab8;
- import java.io.File;
- import java.io.FileReader;
- import java.io.IOException;
- import java.io.LineNumberReader;
- import java.util.Scanner;
- //citesc numerele even de pe liniile odd
- public class readNum {
- public static void read1(String path) {
- try (LineNumberReader lnr = new LineNumberReader(new FileReader(path));) {
- String line = "";
- int nr = 0;
- while ((line = lnr.readLine()) != null)
- {if(Integer.parseInt(line) % 2 == 0 && nr % 2 == 1)
- {System.out.println(line);}nr++;}
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- public static void read2(String path) {
- try(Scanner s = new Scanner(new File(path));){
- while(s.hasNext())
- System.out.println(s.nextInt());
- }catch(IOException ex) {ex.printStackTrace();}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement