Write a main function to get 10 float numbers from user and

Write a main function to get 10 float numbers from user and print the average. Write a main function to get an int N from the user and print the following pattern shown are for N = 4 and N = 5 receptively.

Solution


public class patternexample2 {
   /**
   * @param args
   */
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       int cont=1;
       int space=4;
       for(int i=1;i<=4;i++){
           for(int j=1;j<=space;j++){
               System.out.print(\" \");
              
           }
           for(int k=1;k<=cont;k++){
               System.out.print(\"*\");
              
           }
           System.out.println();
           space=space-1;
           cont=cont+2;
       }
   }
}
output:
*
***
*****
*******

import java.util.*;
public class mymain {
  
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       Scanner sc=new Scanner(System.in);
       int i=1;
       float digit=0.0f;
       float result=0.0f;
       while(i<=10){
       System.out.println(\"enter digits:\");
digit=sc.nextFloat();
result +=digit;
i++;
       }
       System.out.println(\"average of digits is:\"+result/10);
   }
}

output:
enter digits:
10
enter digits:
20
enter digits:
30
enter digits:
40
enter digits:
50
enter digits:
60
enter digits:
70
enter digits:
80
enter digits:
90
enter digits:
100
average of digits is:55.0

 Write a main function to get 10 float numbers from user and print the average. Write a main function to get an int N from the user and print the following patt
 Write a main function to get 10 float numbers from user and print the average. Write a main function to get an int N from the user and print the following patt

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site