import java.util.*;
public class Functions {
public static int calculateProduct(int a, int b) {
return a * b;
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println(calculateProduct(a, b));
}
}
import java.util.*;
public class Functions {
public static void printFactorial(int n) {
//loop
if(n < 0) {
System.out.println("Invalid Number");
return;
}
int factorial = 1;
for(int i=n; i>=1; i--) {
factorial = factorial * i;
}
System.out.println(factorial);
return;
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
printFactorial(n);
}
}
import java.util.*;
public class Functions {
//Multiply 2 numbers
public static int multiply(int a, int b) {
return a*b;
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int result = multiply(a, b);
System.out.println(result);
}
}
import java.util.*;
public class Strings {
public static void main(String args[]) {
StringBuilder sb = new StringBuilder("HelloWorld");
for(int i=0; i
int front = i;
int back = sb.length() - i - 1;
char frontChar = sb.charAt(front);
char backChar = sb.charAt(back);
sb.setCharAt(front, backChar);
sb.setCharAt(back, frontChar);
}
System.out.println(sb);
}
}
Input an email from the user. You have to create a username from the email by deleting the part that comes after ‘@’. Display that username to the user.
Example :
email = “mejona@gmail.com” ; username = “mejona”
email = “helloWorld123@gmail.com”; username = “helloWorld123”
import java.util.*;
public class Strings {
public static void main(String args[]) {
Scanner sc = new Scanner (System.in);
String email = sc.next();
String userName = "";
for(int i=0; i
if(email.charAt(i) == '@') {
break;
} else {
userName += email.charAt(i);
}
}
System.out.println(userName);
}
}
import java.util.*;
public class Strings {
public static void main(String args[]) {
Scanner sc = new Scanner (System.in);
String str = sc.next();
String result = "";
for(int i=0; i
if(str.charAt(i) == 'e') {
result += 'i';
} else {
result += str.charAt(i);
}
}
System.out.println(result);
}
}
import java.util.*;
public class Strings {
public static void main(String args[]) {
Scanner sc = new Scanner (System.in);
int size = sc.nextInt();
String array[] = new String[size];
int totLength = 0;
for(int i=0; i
array[i] = sc.next();
totLength += array[i].length();
}
System.out.println(totLength);
}
}
import java.util.*;
public class Arrays {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int matrix[][] = new int[n][m];
for(int i=0; i
for(int j=0; j
matrix[i][j] = sc.nextInt();
}
}
System.out.println("The transpose is : ");
//To print transpose
for(int j=0; j
for(int i=0; i
System.out.print(matrix[i][j]+" ");
}
System.out.println();
}
}
}
import java.util.*;
public class Arrays {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int matrix[][] = new int[n][m];
for(int i=0; i
for(int j=0; j
matrix[i][j] = sc.nextInt();
}
}
System.out.println("The Spiral Order Matrix is : ");
int rowStart = 0;
int rowEnd = n-1;
int colStart = 0;
int colEnd = m-1;
//To print spiral order matrix
while(rowStart <= rowEnd && colStart <= colEnd) {
//1
for(int col=colStart; col<=colEnd; col++) {
System.out.print(matrix[rowStart][col] + " ");
}
rowStart++;
//2
for(int row=rowStart; row<=rowEnd; row++) {
System.out.print(matrix[row][colEnd] +" ");
}
colEnd--;
//3
for(int col=colEnd; col>=colStart; col--) {
System.out.print(matrix[rowEnd][col] + " ");
}
rowEnd--;
//4
for(int row=rowEnd; row>=rowStart; row--) {
System.out.print(matrix[row][colStart] + " ");
}
colStart++;
System.out.println();
}
}
}
import java.util.*;
public class TwoDArrays {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int rows = sc.nextInt();
int cols = sc.nextInt();
int[][] numbers = new int[rows][cols];
//input
//rows
for(int i=0; i
//columns
for(int j=0; j
numbers[i][j] = sc.nextInt();
}
}
int x = sc.nextInt();
for(int i=0; i
for(int j=0; j
//compare with x
if(numbers[i][j] == x) {
System.out.println("x found at location (" + i + ", " + j + ")");
}
}
}
}
}
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