Advertisement
Guest User

LAB10

a guest
Nov 14th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1.  
  2. package lab.pkg10;
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class LAB10 {
  7. public static int numberOfDaysInAYear(int year){
  8.         if(year%4 == 0 && year%400 ==0)
  9.             return 366;
  10.         else return 365;
  11.  
  12.  
  13.  
  14.  
  15. }
  16.    
  17.     public static int count(String str, char a)
  18. {
  19.    
  20.          int count = 0;        
  21.        for (int i = 0; i < str.length(); i++) {
  22.            if((str.charAt(i))== a)
  23.            {
  24.             count++ ;
  25.            }
  26.               }
  27.        return count;
  28.  
  29. }
  30.     public static double m(int n){
  31.    
  32.     double sum =0;
  33.         for (int i = 1; i <= n; i++) {
  34.             sum -= (double) i/(i+1);
  35.            
  36.            
  37.         }
  38.         return sum;
  39.    
  40.    
  41.     }
  42.     public static void main(String[] args) {
  43.          Scanner input = new Scanner(System.in);  
  44.     /*    System.out.println("i\t  m(i)");
  45.         System.out.println("---------------");
  46.         for (int i = 1; i <= 20; i++) {
  47.             System.out.printf("3%d\t%.4f\n", i, m(i));
  48.         }
  49.      */
  50.         System.out.println("enter a string and  specified character:");
  51.         String str=input.next();
  52.           char a = input.next();  
  53.         count(str , a);
  54.         System.out.println("enter a year");  
  55.         int year= input.nextInt();
  56.         System.out.println("The nmber of days:" + numberOfDaysInAYear(year));
  57.        
  58.     }
  59.    
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement