Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. package com.company.ppj_25;
  2.  
  3. import java.io.FileInputStream;
  4. import java.io.IOException;
  5. import java.sql.SQLOutput;
  6.  
  7. public class Main {
  8. public static void main(String[] args) {
  9.  
  10. int[] array = new int[5*4];
  11.  
  12. try {
  13. FileInputStream fileInputStream = new FileInputStream("P:/knopers/PPJ/input/z2_s18660.bin");
  14.  
  15.  
  16. int tmp = 0;
  17.  
  18. for(int i = 0; tmp != -1; i++) {
  19.  
  20. tmp = fileInputStream.read();
  21. if(tmp != -1) {
  22. array[i] = tmp;
  23. System.out.println(array[i]);
  24. }
  25. }
  26. fileInputStream.close();
  27. // Zapisanie do tablicy wszystkich informacji
  28. }catch(IOException e){
  29. System.out.println(e);
  30. }
  31.  
  32. System.out.println();
  33.  
  34. int[][] arrayByteValues = new int[5][4];
  35.  
  36. for(int i = 0, k = 0; i < 5; i++){
  37. for(int j = 0; j < 4; j++, k++){
  38. arrayByteValues[i][j] = array[k];
  39.  
  40. }
  41. }
  42.  
  43. int[] arrayConverted = new int[5];
  44.  
  45. for(int i = 0; i < 5; i++){
  46. for(int j = 0; j < 4; j++){
  47. arrayConverted[i] += arrayByteValues[i][j] << 8*j;
  48. }
  49. }
  50. System.out.println();
  51.  
  52. int calkowita = 0;
  53. int ulamkowa = 0;
  54. boolean foundCal = false;
  55.  
  56. for(int i = 0; i < arrayConverted.length; i++){
  57. System.out.println(arrayConverted[i]);
  58. if(arrayConverted[i] < 255) {
  59. if (foundCal == false) {
  60. calkowita = arrayConverted[i];
  61. foundCal = true;
  62. }else{
  63. ulamkowa = arrayConverted[i];
  64. }
  65. }
  66. }
  67. System.out.println();
  68.  
  69. System.out.println("Twoj wynik z 3 kolokwium to " + calkowita + "." + ulamkowa);
  70.  
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement