0

Why does not execute else if ?

import java.util.Scanner; public class Programm { public static void main(String args[]){ //Scanner setup Scanner input=new Scanner(System.in); String name; int number; System.out.println("Please enter your course name,which you would like to compelete! "); name=input.nextLine(); if (name.equals("java")){ System.out.println("How many coure do you want to have?"); }else if(name.equalsIgnoreCase("java")){ System.out.println("Sorry we offer only java corse"); } number=input.nextInt(); System.out.prin

1st Dec 2016, 10:08 PM
Mohamed Haque
Mohamed Haque - avatar
18 Réponses
+ 1
Else if statement will only execute if the word "java" is written in a way such that atleast one of the characters is uppercase.
1st Dec 2016, 10:48 PM
Ousmane Diaw
0
the last statement isnt complete
1st Dec 2016, 10:16 PM
kaluo kankadaa
kaluo kankadaa - avatar
0
I recommend JOptionPane. import java.util.Scanner; import javax.swing.JOptionPane; public class myproject { public static void main(String args[]){ //Scanner setup Scanner input = new Scanner(System.in); int number; String name = JOptionPane.showInputDialog("Enter Course name: "); if (name.equals("java")){ System.out.println("How many coure do you want to have?"); }else if(name.equalsIgnoreCase("java")){ System.out.println("Sorry we offer only java corse"); } number=input.nextInt(); } }
1st Dec 2016, 10:24 PM
Nedim Kanat
Nedim Kanat - avatar
0
your else if gets only triggered when input is "java" when written in any case except "java", E.g. Java. I think you missed a ! before your condition
1st Dec 2016, 10:44 PM
Andreas K
Andreas K - avatar
0
import java.util.Scanner; public class Programm { public static void main(String args[]){ //Scanner setup Scanner input=new Scanner(System.in); String name; int number; System.out.println("Please enter your course name,which you would like to compelete! "); name=input.nextLine(); if (name.equals("java")){ System.out.println("How many coure do you want to have?"); }else if(name.equalsIgnoreCase("java")){ System.out.println("Sorry! we offer only java corse"); } number=input.nextInt(); System.out.println("Thank you for chosing our course!!"); } } here is the full code! Where it does not print "sorry!we offer only java course " when I write html?
1st Dec 2016, 10:52 PM
Mohamed Haque
Mohamed Haque - avatar
0
but Why does it not execute "sorry we offer only java Course" when input is HTML??
2nd Dec 2016, 8:43 AM
Mohamed Haque
Mohamed Haque - avatar
0
please post your complete Code, it seems like there is something missing
2nd Dec 2016, 8:48 AM
Andreas K
Andreas K - avatar
0
pleas look down ,I could not post my whole code due to letter limitation
2nd Dec 2016, 8:50 AM
Mohamed Haque
Mohamed Haque - avatar
0
then post the missing part after your line number =input.nextInt(); behind the shown if else if above or give us a link to your code playground code ;)
2nd Dec 2016, 8:52 AM
Andreas K
Andreas K - avatar
0
here is the full code import java.util.Scanner; public class Programm { public static void main(String args[]){ //Scanner setup Scanner input=new Scanner(System.in); String name; int number; System.out.println("Please enter your course name,which you would like to compelete! "); name=input.nextLine(); if (name.equals("java")){ System.out.println("How many coure do you want to have?"); }else if(name.equalsIgnoreCase("java")){ System.out.println("Sorry we offer only java corse"); } number=input.nextInt(); System.out.println("Thank you for chosing our course!!"); }
2nd Dec 2016, 8:55 AM
Mohamed Haque
Mohamed Haque - avatar
0
where do you execute your code?
2nd Dec 2016, 8:58 AM
Andreas K
Andreas K - avatar
0
in eclipse
2nd Dec 2016, 9:01 AM
Mohamed Haque
Mohamed Haque - avatar
0
Try following code. enter "Html" like you do it in your code and tell me the result please. http://www.sololearn.com/app/sololearn/playground/cLq6ud4cd8rb/
2nd Dec 2016, 9:07 AM
Andreas K
Andreas K - avatar
0
now I'm in college.I have not my Laptop. I will tell you later
2nd Dec 2016, 9:10 AM
Mohamed Haque
Mohamed Haque - avatar
0
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String name = scan.nextLine(); if(name.equals("java")){ System.out.println("How many code do you want to have?"); }else if(name.equalsIgnoreCase("java")){ System.out.println("How many course do you want to have"); }else{ System.out.println("Sorry we offer only java course"); } } } I edited your code little bit. But you see in my code that I wanted ,if input is java then execute would "How many course would you want to have? and Scanner will take the course value" now it Print "How many course would you want to have" but It doesn't take the option to input the course value.
2nd Dec 2016, 11:15 PM
Mohamed Haque
Mohamed Haque - avatar
0
I rearranged the code like you want it to use, please try. http://www.sololearn.com/app/sololearn/playground/cLq6ud4cd8rb/
2nd Dec 2016, 11:26 PM
Andreas K
Andreas K - avatar
0
sorry...!It does not work. It is not running in Eclipse and In Solo app it gives all desire output but when Out put is "How many course do you want to have" then I can not give the number of course as input Any way Thank you very much! Where r u from ?
2nd Dec 2016, 11:52 PM
Mohamed Haque
Mohamed Haque - avatar
0
My informatic teacher solved it Now it's all right import java.util.Scanner; public class New { public static void main(String[] args) { Scanner input=new Scanner(System.in); //Scanner setup String name; int value; System.out.print("Please enter your course name:"); name=input.nextLine(); if(name.equalsIgnoreCase("Java")){ System.out.print("How many course do you want to have?:"); value=input.nextInt(); System.out.println("Welcome!You have oredere your course successfully!Thanks for chosing our course"); } else{ System.out.println("Sorry We offer only java course!!"); } } }
7th Dec 2016, 9:39 PM
Mohamed Haque
Mohamed Haque - avatar