import java.util.*;
public class Arrays {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int size = sc.nextInt();
int numbers[] = new int[size];
//input
for(int i=0; i
numbers[i] = sc.nextInt();
}
boolean isAscending = true;
for(int i=0; i
if(numbers[i] > numbers[i+1]) { // This is the condition for descending order
isAscending = false;
}
}
if(isAscending) {
System.out.println("The array is sorted in ascending order");
} else {
System.out.println("The array is not sorted in ascending order");
}
}
}
import java.util.*;
public class Arrays {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int size = sc.nextInt();
int numbers[] = new int[size];
//input
for(int i=0; i
numbers[i] = sc.nextInt();
}
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
for(int i=0; i
if(numbers[i] < min) {
min = numbers[i];
}
if(numbers[i] > max) {
max = numbers[i];
}
}
System.out.println("Largest number is : " + max);
System.out.println("Smallest number is : " + min);
}
}
import java.util.*;
public class Arrays {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int size = sc.nextInt();
String names[] = new String[size];
//input
for(int i=0; i
names[i] = sc.next();
}
//output
for(int i=0; i
System.out.println("name " + (i+1) +" is : " + names[i]);
}
}
}
import java.util.*;
public class Solutions {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a = 0, b = 1;
System.out.print(a+" ");
if(n > 1) {
//find nth term
for(int i=2; i<=n; i++) {
System.out.print(b+" ");
//the concept below is called swapping
int temp = b;
b = a + b;
a = temp;
}
System.out.println();
}
}
}
import java.util.*;
public class Solutions {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n1 = sc.nextInt();
int n2 = sc.nextInt();
while(n1 != n2) {
if(n1>n2) {
n1 = n1 - n2;
} else {
n2 = n2 - n1;
}
}
System.out.println("GCD is : "+ n2);
}
}
import java.util.*;
public class Solutions {
public static void main(String args[]) {
System.out.println("Enter x");
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
System.out.println("Enter n");
int n = sc.nextInt();
int result = 1;
//Please see that n is not too large or else result will exceed the size of int
for(int i=0; i
result = result * x;
}
System.out.println("x to the power n is : "+ result);
}
}
import java.util.*;
public class Solutions {
public static void main(String args[]) {
int positive = 0, negative = 0, zeros = 0;
System.out.println("Press 1 to continue & 0 to stop");
Scanner sc = new Scanner(System.in);
int input = sc.nextInt();
while(input == 1) {
System.out.println("Enter your number : ");
int number = sc.nextInt();
if(number > 0) {
positive++;
} else if(number < 0) {
negative++;
} else {
zeros++;
}
System.out.println("Press 1 to continue & 0 to stop");
input = sc.nextInt();
}
System.out.println("Positives : "+ positive);
System.out.println("Negatives : "+ negative);
System.out.println("Zeros : "+ zeros);
}
}
import java.util.*;
public class Solutions {
public static void main(String args[]) {
do {
} while(true);
}
}
import java.util.*;
public class Solutions {
public static boolean isElligible(int age) {
if(age > 18) {
return true;
}
return false;
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int age = sc.nextInt();
System.out.println(isElligible(age));
}
}
import java.util.*;
public class Solutions {
public static Double getCircumference(Double radius) {
return 2 * 3.14 * radius;
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
Double r = sc.nextDouble();
System.out.println(getCircumference(radius));
}
}
Jump to Page : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53