Untitled
unknown
java
7 months ago
3.4 kB
15
Indexable
Never
//numberthree import java.util.Scanner; public class NumberThree { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter the value of a: "); // 2 int a = scanner.nextInt(); System.out.print("Enter the value of b: "); // 3 | 2*2*2 int b = scanner.nextInt(); int result = 1; for (int i = 1; i <= b; i++) { result *= a; } System.out.println(result); } } //number six import java.util.Scanner; public class NumberSix { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter the value of n: "); int n = scanner.nextInt(); // 7 double sum = 0; for (int i = 1; i <= n; i++) { sum += (double)i / (2 * i - 1); // 7/13 } System.out.println(sum); } } //number seven import java.util.Scanner; public class NumberSeven { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter the value of n: "); int n = scanner.nextInt(); int sum = 0; for (int i = 1; i <= n; i++) { sum += i * i; } System.out.println(sum); } } // number eight import java.util.Scanner; public class NumberEight { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter the value of n: "); int n = scanner.nextInt(); int sum = 0; for (int i = 1; i <= n; i++) { if (i % 2 == 0) { sum -= i; } else { sum += i; } } System.out.println("The value of y is: " + sum); } } // eval one import java.util.Scanner; public class NumberEight { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter the value of N: "); int N = scanner.nextInt(); int sum = 0; for (int i = 1; i <= N; i++) { int innerSum = 0; for (int j = 1; j <= i; j++) { innerSum += j; } sum += innerSum; } sum = -sum; System.out.println("The value of y is: " + sum); } } //eval two import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter even positive integer numbers. Enter an odd number to stop."); while (true) { System.out.print("Enter a positive number: "); int number = scanner.nextInt(); if (number % 2 != 0) { System.out.println("You entered an odd number"); break; } int count = 0; for (int i = 1; i <= number; i++) { if (number % i == 0) { count++; } } System.out.println("Number of divisors of " + number + " is: " + count); } } }
Leave a Comment