CLASSWORK AND CLASS EVAL 04

mail@pastecode.io avatar
unknown
java
2 months ago
2.5 kB
4
Indexable
Never
//eval one

import java.util.Scanner;

public class EvalOne {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
   
    System.out.println("Enter a number");
    int number = sc.nextInt();
   
    System.out.println("Divisors of " + number + ":");
    for (int i = 1;i <= number;i++) {
      if (number % i == 0) {
        System.out.println(i);
      }
   
    }
   
  }

}


//eval two

import java.util.Scanner;

public class EvalTwo {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter number of inputs");
    int number = sc.nextInt();
   
    int non_neg = 0;
    int neg = 0;
   
    for (int i = 1;i <= number; i++) {
      int input_num = sc.nextInt();
      System.out.println("Enter number " + i + ":" + input_num);
     
      if (input_num >= 0) {
        non_neg++;
      }
      else {
        neg++;
      }
    }
   
    System.out.println(non_neg + " Non-negative Numbers");
    System.out.println(neg + " Negative Numbers");
 
  }

}

//classworkone

public class ClassworkOne {
    public static void main(String[] args) {
       int num1 = 24;
       while (num1 > -12) {
           System.out.print(num1 + ",");
           num1 -= 6;
       }
    }
}


//classwork two

import java.util.Scanner;
public class ClassworkTwo {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num_input = sc.nextInt();
        int sum = 0;

        System.out.println("Input the " + num_input + " numbers");
        for (int i=1; i <= num_input; i++) {
            int num = sc.nextInt();
            sum += num;
        }
        System.out.println("The sum of 5 no is: " + sum);

        double avg = sum / num_input;
        System.out.println("The Average is: "+ avg);
    }
}


//classwork three

import java.util.Scanner;

public class ClassworkThree {
    public static void main(String[] args) {
        Boolean not_neg = true;

        while (not_neg == true) {
            Scanner sc = new Scanner(System.in);
            System.out.print("Enter Number: ");
            int num = sc.nextInt();

            if (num < 0) {
                not_neg = false;


            }
            else {
                System.out.println(num * num);

            }

        }


    }

}


Leave a Comment