Advertisement
NB52053

dd

Jun 13th, 2017
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.64 KB | None | 0 0
  1. //PROBLEM 3 ... OPTION 2
  2.  public class Numbers {
  3.  
  4.     int num;
  5.  
  6.     public void showFibonacci() {
  7.         int t1 = 0, t2 = 1, nextTerm = 0;
  8.             for (int i = 1; i <= num; ++i) {
  9.  
  10.             if (i == 1) {
  11.              continue;
  12.             }
  13.  
  14.             if (i == 2) {
  15.                 System.out.printf("  %d  ", t2);
  16.                 continue;
  17.  
  18.             }
  19.             nextTerm = t1 + t2;
  20.             t1 = t2;
  21.             t2 = nextTerm;
  22.             System.out.printf("  %d  ", nextTerm);
  23.  
  24.         }
  25.     }
  26.  
  27.     public void showPyramid(){
  28.          int rowCount = 1;
  29.  
  30.         System.out.println("Here Is the Pyramid");
  31.  
  32.             if (num <=9 ) {
  33.  
  34.     for (int i = num; i > 0; i--) {
  35.  
  36.         for (int j = 1; j <= i * 2; j++) {
  37.             System.out.print(" ");
  38.         }
  39.  
  40.         for (int j = 1; j <= rowCount; j++) {
  41.             System.out.print(j + " ");
  42.         }
  43.  
  44.         for (int j = rowCount - 1; j >= 1; j--) {
  45.             System.out.print(j + " ");
  46.         }
  47.  
  48.         System.out.println();
  49.  
  50.         rowCount++;
  51.     }
  52.  
  53.     }
  54.    }
  55. }
  56.  
  57.     public boolean checkNumber(){
  58.  
  59.         boolean even = true;
  60.         if (num%2!=0){
  61.             even = false;
  62.         }
  63.         return true;
  64.     }
  65.  
  66.     void setNum(int num){
  67.  
  68.  
  69.     }
  70. }
  71.  
  72.  ////////////////////////////////////////////
  73. import java.util.Scanner;
  74.  
  75. public class NumberTest {
  76.  
  77.     public static void main(String[] args) {
  78.  
  79.         Scanner sc = new Scanner(System.in);
  80.         Numbers test = new Numbers();
  81.         int select = sc.nextInt();
  82.  
  83.         test.num = 5;
  84.  
  85.     switch (select) {
  86.  
  87.              case 1:test.showFibonacci();
  88.              break;
  89.  
  90.              case 2:test.showPyramid();
  91.              break;
  92.  
  93.              case 3: test.checkNumber();
  94.              break;
  95.  
  96.              case 4:test.setNum(0);
  97.         }
  98.  
  99.     }
  100. }
  101.  
  102.  
  103. ///////////////////////////////////////////////////////////////////////////////////////////////////
  104.  
  105. public class ArrayCheck{
  106.  
  107.  public static void main(String[] args) {
  108.      
  109.        
  110.         int sum =0;
  111.         int max=0;
  112.         int min=0;
  113.        
  114.        int[] grades=new int[]{
  115.            2,3,9,8,13,1,5,19,-8,0,4
  116.        };
  117.        for(int i=0;i<grades.length;i++){
  118.            sum+=grades[i];
  119.                
  120.            if (max<grades[i]){
  121.                max=grades[i];
  122.            }
  123.            if (min>grades[i]){
  124.                min=grades[i];}
  125.            }
  126.         double average = (double) sum / grades.length;
  127.        System.out.println("  min:" + min);
  128.         System.out.println("  max:" + max);
  129.         System.out.println("  average:" + average);
  130.        }
  131.        }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement