Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class homework
- {
- public static Scanner reader = new Scanner(System.in);
- public static void Q21() {
- int n, c = 0;
- for (int i = 1; i < 9; ++i) {
- System.out.print("Enter number: ");
- n = reader.nextInt();
- if (n % 2 == 0) c++;
- }
- System.out.println(c);
- }
- public static void Q22() {
- int c = 0;
- for (int i = 1; i < 301; ++i) {
- if (Math.sqrt(i) == (int)(Math.sqrt(i))) c++;
- }
- System.out.println(c);
- }
- public static void Q25() {
- System.out.print("Enter the number of people that atend the test: ");
- int n = reader.nextInt();
- int mistake, c = 0;
- for (int i = 0; i < n; ++i){
- System.out.print("Number of mistake in signs: ");
- mistake = reader.nextInt();
- if (mistake == 0){
- System.out.print("Number of mistake over all: ");
- mistake = reader.nextInt();
- if (mistake < 4) c++;
- }
- }
- System.out.println("Number of people that pass: " + c);
- System.out.println("Pass rate: " + c*100.0/n);
- }
- public static void Q27() {
- System.out.print("Enter number: ");
- int n = reader.nextInt();
- for (int i = 2; i < n; ++i) {
- if (n % i == 0) return;
- }
- System.out.println(n + " is a prime number");
- }
- public static void Q33() {
- int n, c = 0;
- for (int i = 0; i < 30; ++i) {
- System.out.print("Enter number: ");
- n = reader.nextInt();
- if (n > 9 && n < 100) c += n;
- }
- System.out.println("The sum of the even numbers: " + c);
- }
- public static void Q34() {
- System.out.print("Enter number: ");
- int n = reader.nextInt();
- int assembly = 1;
- for (int i = 1; i < n; ++i) {
- assembly *= i;
- }
- System.out.println("The assembly for" + n + "is: " + assembly);
- }
- public static void Q36() {
- System.out.println("-------------Q36-------------");
- System.out.print("Enter number: ");
- int n1 = reader.nextInt();
- System.out.print("Enter number: ");
- int n2 = reader.nextInt();
- int max = Math.max(n1,n2), min = Math.min(n1, n2);
- int sum = 0, mul = 1;
- for (int i = min; i < max; ++i) {
- sum += i; mul *= i;
- }
- System.out.println("The sum is: " + sum + ", and the product is: " + mul);
- }
- public static void Q38() {
- System.out.println("-------------Q38-------------");
- System.out.print("Enter base of exponent: ");
- int base = reader.nextInt();
- System.out.print("Enter exponent: ");
- int exp = reader.nextInt();
- for (int i = 1; i < exp; ++i) {
- base *= base;
- }
- System.out.println("The exponent is: " + base);
- }
- public static void Q39() {
- System.out.println("-------------Q39-------------");
- System.out.print("Enter number: ");
- int n = reader.nextInt();
- int c = 0;
- for (int i = 1; i < n; ++i) {
- if (n % i == 0) {
- c += i;
- }
- }
- if (c == n) {
- System.out.println(n + " is perfect number");
- for (int i = 1; i < n; ++i) {
- if (n % i == 0) { System.out.print(i + " + "); }
- }
- }
- }
- public static void main(String[] args)
- {
- Q21();Q22();Q25();Q27();Q33();Q34();Q36();Q38();Q39();
- }
- }
Advertisement
Advertisement