Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.Scanner;
- public class Main {
- private static int inputN(){
- int n;
- boolean isCorrect;
- n = 0;
- isCorrect = false;
- Scanner sc = new Scanner(System.in);
- while(!isCorrect){
- System.out.println("Enter n - amount of days in month");
- n = sc.nextInt();
- if(n < 28 || n > 31){
- System.out.println("Incorrect input N");
- }else{
- isCorrect = true;
- }
- }
- sc.close();
- return n;
- }
- private static int[] inputFromFile(int n){
- String pathname = "";
- int counter;
- counter = 0;
- int[] days;
- days = new int[n];
- Scanner in = null;
- try {
- in = new Scanner(new File("input.txt"));
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- for(int i = 0; i < n; i++){
- days[i] = in.nextInt();
- if(days[i] < 0){
- counter++;
- }
- }
- for(int i = 0; i < n; i++){
- System.out.print(days[i] + ' ');
- }
- in.close();
- System.out.println("COUNTER = " + counter);
- return days;
- }
- public static void main(String[] args) throws FileNotFoundException {
- int counter, n;
- counter = 0;
- n = 0;
- int[] days;
- System.out.println("This program...");
- n = inputN();
- days = new int[n];
- days = inputFromFile(n);
- System.out.println("There are " + counter + " days with temperature < 0 degrees");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement