OOPs, Classes, Methods

ARRAY - FOR EACH LOOP

Sample Input and Output :
 

Enter n :
3
Enter numbers : 
100
23
15

Enter strings : 
hi
hello
welcome

Displaying numbers
100
23
15
Displaying strings
hi
hello
welcome


CODE:

import java.util.Scanner; 

public class Main{ 

public static void main (String[] args) {

Scanner scnr=new Scanner(System.in);

int n;

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

n=scnr.nextInt();

int num[]=new int[n];

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

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

num[i]=scnr.nextInt();

}

String str[]=new String[n];

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

for(int j=0; j<n; j++) {

str[j]=scnr.next();

}

System.out.println("Displaying numbers");

for(int m:num) {

System.out.println(m);

}

System.out.println("Displaying strings");

for(String p:str) {

System.out.println(p);

}




Comments

Popular posts from this blog