0% found this document useful (0 votes)
34 views

Java Lab

This document contains 5 Java programs: 1) A program that prints a pattern of 0s and 1s using nested for loops and modulo operation. 2) A program that finds the highest number in an integer array by taking input from the user. 3) A program that checks if a given number is even or odd using modulo operation. 4) A program that takes a name as input from the user and prints it back. 5) No program is shown for the last section.

Uploaded by

Animesh Mani
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)
34 views

Java Lab

This document contains 5 Java programs: 1) A program that prints a pattern of 0s and 1s using nested for loops and modulo operation. 2) A program that finds the highest number in an integer array by taking input from the user. 3) A program that checks if a given number is even or odd using modulo operation. 4) A program that takes a name as input from the user and prints it back. 5) No program is shown for the last section.

Uploaded by

Animesh Mani
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/ 3

1. Write a java program to print like Pattern type.

public class Pattern {


public static void main(String args[]) {
for (int i = 0; i <= 5; i++) {
for (int j = 0; j < i; j++) {
if ((i + j) % 2 == 0)
System.out.print("0");
else
System.out.print("1");
}
System.out.println();
}
}
}

Output:-

2. Write a java program to cheek the highest number in the array.


import java.io.*;
public class ArrayClass {
public static void main(String[] args)
{
int n[], n1 = 0, h, i;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the size of the array :");
try {
n1 = Integer.parseInt(br.readLine());
n = new int[n1];
System.out.println("Enter array elements :");
for (i = 0; i < n1; i++) {

n[i] = Integer.parseInt(br.readLine());
}
h = n[0];
for (i = 1; i < n1; i++) {
if (n[i] > h)
h = n[i];
}
System.out.println("Highest number = " + h);
} catch (IOException e) {
System.out.println(e);
}

1|Page
}
}
Output:-

3. Write a java program to know a number is Even or Odd


import java.io.*;
import java.lang.*;
class EvenOdd
{
public static void main(String args[])throws IOException
{
int n=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter number: ");
n=Integer.parseInt(br.readLine());
n=n%2;
if(n==0)
System.out.println("The given number is even ");
else
System.out.println("The given number is odd ");
}
}

Output:-

2|Page
4. Write a java program taking user input name and again print.

import java.io.*;
public class Name
{
public static void main(String args[])throws IOException
{
String name;
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter name: ");
name=br.readLine();
System.out.println("Name is: "+name);
}
}
Output:-

5.

3|Page

You might also like