How can use a function ( if ) on javascript [closed]
import java.util.Scanner;
public class nothing
{
public static void main ( String arge[] )
{
Scanner input = new Scanner ( System.in );
int mork;
int mork1;
int mork2;
int mork3;
System.out.print ( " Enter The mork ");
mork = input.nextInt();
if (mork > 90 )
System.out.print("A");
if ( mork1 > 80)
System.out.print("B");
if ( mork2 > 70)
System.out.print("C");
if (mork3 >= 60)
System.out.print(开发者_StackOverflow中文版"D");
else System.out.print("H");
}
That's definitely JAVA not JavaScript...
[EDIT]
Here is valid way to do a if/else if/else statment in Java, if that's what you're asking...
import java.util.Scanner;
public class nothing {
public static void main( String[] args ) {
Scanner input = new Scanner( System.in );
int mork;
int mork1; // <--- never used...
int mork2; // <--- never used...
int mork3; // <--- never used...
System.out.print( " Enter the mork " );
mork = input.nextInt();
if( mork > 90 ) {
System.out.print( "A" );
}else if( mork > 80 ) { // <-- changed mork1 to mork since mork1 is never initialized
System.out.print( "B" );
}else if( mork > 70 ) { // <-- changed mork2 to mork since mork2 is never initialized
System.out.print( "C" );
}else if( mork >= 60 ) { // <-- changed mork3 to mork since mork3 is never initialized
System.out.print( "D" );
}else{
System.out.print( "H" );
}
}
}
精彩评论