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
18 Answers
+ 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.
0
the last statement isnt complete
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();
}
}
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
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?
0
but Why does it not execute "sorry we offer only java Course" when input is HTML??
0
please post your complete Code, it seems like there is something missing
0
pleas look down ,I could not post my whole code due to letter limitation
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 ;)
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!!");
}
0
where do you execute your code?
0
in eclipse
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/
0
now I'm in college.I have not my Laptop. I will tell you later
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.
0
I rearranged the code like you want it to use, please try.
http://www.sololearn.com/app/sololearn/playground/cLq6ud4cd8rb/
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 ?
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!!");
}
}
}