Programming Fundamentals: by Imran Kazmi
Programming Fundamentals: by Imran Kazmi
Lecture 10
By
Imran Kazmi
In the previous lecture, were working
on “ Array” and some programming
practices has been given.
import java.io.*;
public class array {
public static void main(String[] args)throws Exception
{
int n,i;
int [] x=new int[5];
BufferedReader str=new BufferedReader(new InputStreamReader(System.in));
enter five
String s;
System.out.println(" enter five values ");
values
for(i=0;i<=4;i++) 10
{ 20
s =str.readLine(); 30
n=Integer.parseInt(s); 40
x[i]=n; 50
} Multiple of
System.out.println("Multiple of two of each value"); two of each
for(i=0;i<=4;i++)
value
{
20
System.out.println(x[i]*2);
}
40
} 60
} 80
100
Write down the program to display the even values from the given array of ten values
import java.io.*;
public class array { enter ten
public static void main(String[] args)throws Exception values
{
10
int n,i;
int [] x=new int[10];
15
BufferedReader str=new BufferedReader(new InputStreamReader(System.in)); 20
String s; 25
System.out.println(" enter ten values "); 30
for(i=0;i<=9;i++)
35
{
s =str.readLine();
40
n=Integer.parseInt(s); 45
x[i]=n; 50
} 55
System.out.println("Even values are");
Even values
for(i=0;i<=9;i++)
{ are
if(x[i]%2==0) 10
System.out.println(x[i]); 20
} 30
}
40
}
50