+ 1
What is wrong here?
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner old=new Scanner(System.in ); System .out.println("enter a number"); System .out.println("you entered"+old.nextInt); int new=old%2 if(new=0){ System.out.println("it is a even no."); } else{ System.out.println("it is a odd no."); } } }
6 odpowiedzi
+ 3
i took a look at your code and there was infact series of errors so i worked on it a bit and here
public static void main(String[] args) {
Scanner anything=new Scanner(System.in );
int old = anything.nextInt();
System .out.println("enter a number");
System .out.println("you entered "+old);
int X = 2 %old;
if(X==0){
System.out.println("it is a even no.");
} else{
System.out.println("it is a odd no.");
}
}
besides i have wrote a code like this, take a look at another method to achieve that
https://code.sololearn.com/ccfRRifElzY5/#java
hope you understood the errors by comparing the three codes.....
+ 3
@Bakel
you must write
int X = old % 2;
+ 3
@Rishabh Agrawal
Thanks man that was a little error
int x= old % 2
Instead of 2%old.
+ 1
fix old.nextint with old.nextInt() and new =0 with new==0
0
if ( new == 0)
this will work.