Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //PROBLEM 3 ... OPTION 2
- public class Numbers {
- int num;
- public void showFibonacci() {
- int t1 = 0, t2 = 1, nextTerm = 0;
- for (int i = 1; i <= num; ++i) {
- if (i == 1) {
- continue;
- }
- if (i == 2) {
- System.out.printf(" %d ", t2);
- continue;
- }
- nextTerm = t1 + t2;
- t1 = t2;
- t2 = nextTerm;
- System.out.printf(" %d ", nextTerm);
- }
- }
- public void showPyramid(){
- int rowCount = 1;
- System.out.println("Here Is the Pyramid");
- if (num <=9 ) {
- for (int i = num; i > 0; i--) {
- for (int j = 1; j <= i * 2; j++) {
- System.out.print(" ");
- }
- for (int j = 1; j <= rowCount; j++) {
- System.out.print(j + " ");
- }
- for (int j = rowCount - 1; j >= 1; j--) {
- System.out.print(j + " ");
- }
- System.out.println();
- rowCount++;
- }
- }
- }
- }
- public boolean checkNumber(){
- boolean even = true;
- if (num%2!=0){
- even = false;
- }
- return true;
- }
- void setNum(int num){
- }
- }
- ////////////////////////////////////////////
- import java.util.Scanner;
- public class NumberTest {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- Numbers test = new Numbers();
- int select = sc.nextInt();
- test.num = 5;
- switch (select) {
- case 1:test.showFibonacci();
- break;
- case 2:test.showPyramid();
- break;
- case 3: test.checkNumber();
- break;
- case 4:test.setNum(0);
- }
- }
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- public class ArrayCheck{
- public static void main(String[] args) {
- int sum =0;
- int max=0;
- int min=0;
- int[] grades=new int[]{
- 2,3,9,8,13,1,5,19,-8,0,4
- };
- for(int i=0;i<grades.length;i++){
- sum+=grades[i];
- if (max<grades[i]){
- max=grades[i];
- }
- if (min>grades[i]){
- min=grades[i];}
- }
- double average = (double) sum / grades.length;
- System.out.println(" min:" + min);
- System.out.println(" max:" + max);
- System.out.println(" average:" + average);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement