mardi 30 novembre 2021

How to add the conditional if in file text in java [closed]

I have a text file that includes several temperatures, but I only wanna print out the ones that are above 20. How can I make that possible? I know how to print and reach the text file but how can I make the program print only the temperatures higher than 20 or so. Basically what I am looking for is how to use if statement on a java text so I can print out only the required info.

public static void main(String[] args) throws Exception {




File f = new File ("C:/packages.txt");
Scanner sc = new Scanner (f);
String s;
while (sc.hasNextLine()){

s = sc.nextLine(); 
System.out.println(s);

    
    }
sc.close();
}
}

This is what I have worked on so far

Aucun commentaire:

Enregistrer un commentaire