0% found this document useful (0 votes)
3 views3 pages

Java Codes

The document contains two Java programs. The first program collects various user inputs related to personal information and displays them, while the second program performs operations on an array, including input, sum, average, finding maximum and minimum values, searching for an element, and reversing the array. Both programs utilize the Scanner class for user input and demonstrate basic data types and array manipulation in Java.

Uploaded by

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

Java Codes

The document contains two Java programs. The first program collects various user inputs related to personal information and displays them, while the second program performs operations on an array, including input, sum, average, finding maximum and minimum values, searching for an element, and reversing the array. Both programs utilize the Scanner class for user input and demonstrate basic data types and array manipulation in Java.

Uploaded by

macos47119
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

// Code 1 - Dataypes :

import [Link];

public class DataTy


{
public static void main (String [] args)
{
Scanner sc = new Scanner ([Link]);
[Link] ("Enter your age : ");
byte age = [Link]();

[Link] ("Enter the class strength : ");


short strength = [Link]();

[Link] ("Enter the salary : ");


int salary = [Link]();

[Link] ("Enter the Country Population : ");


long population = [Link]();

[Link] ("Enter your height in feet : ");


float height = [Link]();

[Link] ("Enter your Percentage : ");


double percentage = [Link]();

[Link] ("Enter your Grade : ");


char grade = [Link]().charAt(0);

[Link]("Are you a student? : ");


boolean isStudent = [Link]();

[Link] ("\n ------ Output ------ ");


[Link] ("Age : " + age);
[Link] ("Strength : " + strength);
[Link] ("Salary : " + salary );
[Link] ("Population : " + population );
[Link] ("Height : " + height );
[Link] ("Percentage : " + percentage );
[Link] ("Grade : " + grade );
[Link] ("Student : " + isStudent );

[Link]();
}
}
// Code 2 - Operations on array

import [Link];
class Array
{
public static void main (String [] args)
{
Scanner sc = new Scanner ([Link]);

int [] a = new int [5];


int sum = 0;

[Link] ("Enter 5 elements : ");


for (int i = 0 ; i<5; i++)
{
a[i] = [Link]();
}

//Display
[Link]("Array Elements : ");
for (int i = 0 ; i<5; i++)
{
[Link](a[i] + " ");
sum += a[i];
}

//Sum
[Link] ("Sum of elements : " + sum);

//Average
double avg = sum/5.0;
[Link] ("Average of elements : " + avg);

//Maximum and Minimum Element


int max = a [0];
int min = a [0];
for ( int i = 1; i < 5; i++)
{
if (a[i] > max)
max = a [i];
if (a[i] < min)
min = a [i];
}
[Link] ("Maximum element : " + max);
[Link] ("Minimum element : " + min);

//Search element
[Link] ("Enter element to search : ");
int key = [Link] ();
boolean found = false ;
for (int i = 0 ; i<5; i++)
{
if ( a[i] == key )
{
[Link] ("Element found at index : " + i );
found = true;
break;
}
}
if (! found)
{
[Link] (" Element not found " );
}

//Reverse array
[Link] ("Reversed array : " );
for ( int i = 4; i >= 0; i-- )
{
[Link] (a[i] + " ");
}
}
}

You might also like