Problem Name: 1064 Positives and Average solution
Problem Number : URI - 1064 Positives and Average code
Online Judge : URI Online Judge Solution
Category: Beginner
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
float n1,total = 0,average = 0;
int totalNumber = 0;
Scanner sc =new Scanner(System.in);
for (int i = 1; i <= 6; i++) {
n1 =sc.nextFloat();
if (n1 > 0) {
totalNumber += 1;
total += n1;
}
}
average = total / totalNumber;
System.out.print(totalNumber+" valores positivos\n");
System.out.printf("%.1f\n",average);
}
}
Problem Number : URI - 1064 Positives and Average code
Online Judge : URI Online Judge Solution
Category: Beginner
Solution in JAVA
import java.io.IOException;import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
float n1,total = 0,average = 0;
int totalNumber = 0;
Scanner sc =new Scanner(System.in);
for (int i = 1; i <= 6; i++) {
n1 =sc.nextFloat();
if (n1 > 0) {
totalNumber += 1;
total += n1;
}
}
average = total / totalNumber;
System.out.print(totalNumber+" valores positivos\n");
System.out.printf("%.1f\n",average);
}
}
No comments:
Post a Comment
Thanks..