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
Post a Comment