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

Programming Fundamentals: by Imran Kazmi

This document summarizes the 10th lecture on programming fundamentals. It discusses solving programming assignments on arrays from the previous lecture. The assignments are to: 1) Display an array in reverse order, 2) Find the largest value in an array, 3) Display multiples of 2 for each array element, 4) Display even values in an array. It then provides sample Java code solutions for each assignment in the output section.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Programming Fundamentals: by Imran Kazmi

This document summarizes the 10th lecture on programming fundamentals. It discusses solving programming assignments on arrays from the previous lecture. The assignments are to: 1) Display an array in reverse order, 2) Find the largest value in an array, 3) Display multiples of 2 for each array element, 4) Display even values in an array. It then provides sample Java code solutions for each assignment in the output section.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Programming Fundamentals

Lecture 10
By
Imran Kazmi
 In the previous lecture, were working
on “ Array” and some programming
practices has been given.

 In this lecture, we will discuss the


solutions of the given programming
assignments/practices
 Write down the program to display the array
in reverse order.
 Write down the program to find the largest
value from the array of 10 values.
 Write down the program to display the
multiple of 2 of each element of the array.
 Write down the program to display the even
values from the given array of ten values.
Output
Display the values of the array in reverse order using JAVA
import java.io.*;
public class array {
enter ten
public static void main(String[] args)throws Exception values
{ 10
int n,i; 20
int [] x=new int[10]; 30
BufferedReader str=new BufferedReader(new InputStreamReader(System.in)); 40
String s;
50
System.out.println(" enter ten values ");
for(i=0;i<=9;i++)
60
{ 70
s =str.readLine(); 80
n=Integer.parseInt(s); 90
x[i]=n; 100
}
values in
System.out.println("values in reverse order are");
for(i=9;i>=0;i--)
reverse order
{ are
System.out.println(x[i]); 100
90
} 80
} 70
}
60
50
Output
Write down the program to find the largest value from the array of 10 values using JAVA
import java.io.*;
public class array {
public static void main(String[] args)throws Exception
{
int n,i,large;
int [] x=new int[10];
BufferedReader str=new BufferedReader(new InputStreamReader(System.in));
String s; enter ten values
System.out.println(" enter ten values ");
10
for(i=0;i<=9;i++)
{
20
s =str.readLine(); 70
n=Integer.parseInt(s); 90
x[i]=n; 33
} 44
large=x[0]; 55
for(i=1;i<=9;i++)
12
{
if(x[i]>large)
14
large=x[i]; 18
} Largest value=90
System.out.println("Largest value="+large);
}
}
Write down the program to display the multiple of 2 of each element of the array

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

You might also like