import java.util.Scanner;
public class Evenodd
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int e=0,o=0,so=0,se=0,i;
System.out.println("enter 15 number");
for(i=1;i<=15;i++)
{
int a=sc.nextInt();
}
{
if(a%2==0)
e++;
se=a+se;
}
{
else
o++;
so=a+so;
}
System.out.println("Sum of odd number"+o);
System.out.println("Sum of even number"+se);
System.out.println("no of odd number"+e) ;
System.out.println("no of odd number"+o);
}
}
not compiling and it is showing else without if.....
No rubbish answers
Answers
Answer:
Taking Input in Java
We make computer programs for users. We solve real-world computer problems for users. So, it is necessary for our computer to interact with the users. This is what you will learn in this chapter.
We are done with operators and know how to print something on the screen. In this section, we will learn about how to take input from a user. So, yeah now you can take input from a user and display something on the screen. Let's proceed.
In Java, we input with the help of the Scanner class. Java has a number of predefined classes which we can use. We will learn more about classes later.
Predefined classes are organized in the form of packages. This Scanner class is found in java.util package. So to use the Scanner class, we first need to include java.util package in our program.
We include a package in a program with the help of import keyword. We can either import the java.util.Scanner class or the entire java.util package.
To import a class or a package, add one of the following lines to the very beginning of your code.
import java.util.Scanner; // This will import just the Scanner class
import java.util.*; // This will import the entire java.util package
After importing, we need to write the following statement in our program.
Scanner s = new Scanner (System.in);
Here by writing Scanner s, we are declaring s as an object of Scanner class. System.in within the round brackets tells Java that this will be System Input i.e. input will be given to the system.
If you have understood all that has been stated till now, it's a good thing. If you haven't, do not bother. Currently, you just need to know that we have to import the class or package at the beginning of the program and then include the above line in the program.
How to Input
Taking a value from a user is quite easy. You just have to write a statement and it's done!
Let's start with integer. Consider the following code.