Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners I don't know how to use counter variable in this Qustion ....:(
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


MD MidoO
I don't know how to use counter variable in this Qustion ....:(
1 Answer(s)      3 years and 4 months ago
Posted in : Java Beginners


Declare and initialize value of array in int type. read and assgin all the mark to every students by using counter variable, k.

output should be like this; Students marks: student 1 : 10 student 2 : 15 student 3 : 89 student 4 : 56 student 5 : 76


Advertisement
View Answers

June 22, 2011 at 10:46 AM


import java.util.*;
class ArrayExample
{
    public static void main(String[] args) 
    {
        Scanner input=new Scanner(System.in);
        System.out.println("Enter Marks of 5 students: ");
        int marks[]=new int[5];
            for(int k=0;k<marks.length;k++){
            marks[k]=input.nextInt();
        }
        System.out.println("Student's Marks: ");
        for(int k=0;k<marks.length;k++){
            int i=k+1;
            System.out.println("student "+i+": "+marks[k]);
        }
    }
}


Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com