Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
52 views4 pages

Java Lab

The document contains multiple Java programs that demonstrate various functionalities such as inputting numbers into an array, counting even and odd numbers, concatenating strings, and calculating powers of a number. Each program utilizes the Scanner class for user input and performs specific operations based on the input provided. The code snippets showcase basic programming concepts and array manipulations in Java.

Uploaded by

Saira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views4 pages

Java Lab

The document contains multiple Java programs that demonstrate various functionalities such as inputting numbers into an array, counting even and odd numbers, concatenating strings, and calculating powers of a number. Each program utilizes the Scanner class for user input and performs specific operations based on the input provided. The code snippets showcase basic programming concepts and array manipulations in Java.

Uploaded by

Saira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

import java.util.

*;

public class Lab_1 {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

int [] my_Array = new int[5];

for(int i = 0; i < 5; i++){

System.out.print("Enter "+ "number"+ i+ ": ");

my_Array[i] = input.nextInt();

String my_str = Arrays.toString(my_Array);

System.out.print("Original Array is : ");

System.out.println(my_str);

count_even_odd_num(my_Array, 5);

public static void count_even_odd_num(int [] my_Arr, int size){

int Odd_Count = 0;

int Even_Count = 0;

for(int i = 0; i < size; i++){

if(my_Arr[i] != 0){

if(my_Arr[i] % 2 == 0){

Even_Count++;
}

else{

Odd_Count++;

System.out.println("Even numbers = " + Even_Count);

System.out.println("Odd numbers = " + Odd_Count);

import java.util.*;

public class java {

public static void main(String[] args){

Scanner input = new Scanner(System.in);

System.out.println("Enter String 1: ");

String str1 = input.nextLine();

System.out.println("Enter String 1: ");

String str2 = input.nextLine();

System.out.println("After concatenation : ");

concat(str1, str2);

public static void concat(String s1, String s2){


String string_after_concat = s1.concat(" "+ s2);

System.out.println(string_after_concat);

import java.util.*;

public class java {

public static void main(String[] args){

Scanner input = new Scanner(System.in);

// Initialising Array with user input

System.out.println("Enter size for array");

int size = input.nextInt();

int[] arr = new int[size];

int sum = 0;

for(int i = 0; i < size; i++){

arr[i] = input.nextInt();

import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.println("Enter number: ");


int number = input.nextInt();

System.out.println("Enter power:");
int power = input.nextInt();

int result = (int) (pow(number,power));


System.out.println(number + " raised to the power " + power + " is = "
+ result);

}
public static double pow(int number, int power){
double ans = Math.pow(number, power);
return ans;
}
}

You might also like