KonradKonieczny

Ćwiczenia nr 3 - zadanie 7

Jan 16th, 2022 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. package com.jetbrains;
  2. import java.util.Scanner;
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5.  
  6. public class lista3_zad7
  7. {
  8.     public static void main(String[] args) throws FileNotFoundException
  9.     {
  10.         File file = new File("NAPIS.txt");
  11.         Scanner inp = new Scanner(file);
  12.  
  13.         String napis;
  14.         int linia = 0;
  15.         boolean asc;
  16.         while(inp.hasNextLine())
  17.         {
  18.             linia++;
  19.             napis = inp.nextLine();
  20.             asc = true;
  21.             // checking if napis is ascending string in ascii
  22.             for(int i = 0; napis.length() - 1 > i; i++)
  23.             {
  24.                 char a1 = napis.charAt(i);
  25.                 char a2 = napis.charAt(i+1);
  26.  
  27.                 if ( (int) a1 >= (int) a2 )
  28.                 {
  29.                     asc = false;
  30.                     break;
  31.                 }
  32.             }
  33.  
  34.             // we assumed that is true and if our checking failed this going to be true
  35.             if(asc)
  36.             {
  37.                 System.out.println(linia + " " + napis);
  38.                 for(int i = 0; napis.length() > i; i++)
  39.                 {
  40.                     char c = napis.charAt(i);
  41.                     if(i != napis.length() - 1) System.out.print((int) c + " < ");
  42.                     else System.out.print((int) c);
  43.                 }
  44.                 System.out.println();
  45.                 System.out.println();
  46.             }
  47.         }
  48.  
  49.         inp.close();
  50.     }
  51. }
Add Comment
Please, Sign In to add comment