+ 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."); } } }

31st Dec 2017, 4:42 PM
Hardik Sonkar
Hardik Sonkar - avatar
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.....
31st Dec 2017, 5:10 PM
Bakel
Bakel - avatar
+ 3
@Bakel you must write int X = old % 2;
31st Dec 2017, 5:09 PM
Rishabh Agrawal
Rishabh Agrawal - avatar
+ 3
@Rishabh Agrawal Thanks man that was a little error int x= old % 2 Instead of 2%old.
31st Dec 2017, 6:19 PM
Bakel
Bakel - avatar
+ 1
fix old.nextint with old.nextInt() and new =0 with new==0
31st Dec 2017, 5:02 PM
Haileyesus Shitalem
Haileyesus Shitalem - avatar
0
if ( new == 0) this will work.
31st Dec 2017, 4:58 PM
Rishabh Agrawal
Rishabh Agrawal - avatar