About Our Blog

Blogroll

Blogger templates

Input, array and for loop snippet program (Java sample tha let user input six(6) integer values then display them, find total and average)



Java sample program that let user to enter six(6) random integer values then display them, find its total and average

 
import java.util.Scanner;
class maquery3
{
 public static void main(String[]args)
  {
   Scanner y = new Scanner(System.in);
   int m;
   double sum = 0, avg;
   int num[] = new int[7];
   System.out.println();
   System.out.println();
   System.out.println();
   System.out.println("Enter 6 randoms numbers");
   for(m=1;m<=6;m++)
    {
     num[m] = y.nextInt();
    }
   System.out.println();
   System.out.println();
   System.out.println();
   for(m=1;m<=6;m++)
    {
     System.out.println(num[m]);
     sum += num[m];
  
 }

   avg = sum/6;
   System.out.println("The total of numbers is " + sum + " and The avarage is "+avg);
  }
}




Javasnipetprogram.jpg
Snapshots from notepad 


Javasnippetprgcmd.jpg
Result of the above codes,
The red line just separate user inputs and result from user inputs 

No comments :

Post a Comment

 

What do you want to know?

Simple Programing (creating your own useful programs or simple programs for funny)

Simple hacking tricks (funny tricks like Facebook friends accounts hacking tricks etc.)
Notepad tricks and codes
Cmd tricks and codes e.tc.

This blog is still in progress anything which does not posted yet you can request it, you can use this email: steven_washokera@yahoo.com or just write what you want to learn in the comment box and then I 'll post it to you ASAP! (I 'll make it first)

Ads