JAVA) Calculate average and sum using JAVA~!!

Hello~~
I`m lulu~!!

Today, I`m going to show you how to calculate average and sum using Java programming language.

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);  //import java.util.Scanner; 

//or you can just press "Alt+shift+o" than eclipse will automatically import scanner.
System.out.println("Name : ");
String name = sc.next();
System.out.println("Your java score : ");
int java = sc.nextInt();
System.out.println("Your python score : ");
int pyth = sc.nextInt();
System.out.println("===================================");
System.out.println(name + "'s total score : " + (java + pyth) + "," + "average : " + (java + pyth)/2.0);
//if you will use sum in other situation, you can define
                       // int total = java + pyth; or you can use these codes using "double"                           //when there is floating number
/* In advance, if you want to print some words that says study more that                     * has lower subject, you can use these codes.
*/

if(java<pyth) {
System.out.println("Study more java programming language!!");
}
else if(java>pyth) {
System.out.println("Study more python programming language!!");
}
else {
System.out.println("Study both java and python programming language!!");
}
}



I'll post many other interesting games or codes using many variable programming languages.   :-)


If you have any questions or any opinions, tell me you'll be welcomed :-)
Thank you




Comments

Popular posts from this blog

C언어) C언어를 이용하여 평균 구하기~!!

파이썬) 파이썬으로 사칙연산 계산기 만들기~!!

C언어) C언어를 이용하여 나의 BMI 측정하기(저체중, 표준체중, 과체중) 여러분도 직접 비만도를 측정해보세요~!!