Вы находитесь на странице: 1из 8

Question_1

Negative or Positive : package tutorial_4;


import java.util.Scanner;
public class Q_1 {
public static void main (String[] args){
System.out.print("Enter an Integer Number= ");
Scanner input= new Scanner (System.in);
int x=input.nextInt();
if(x>0)
System.out.println("The Number is Positive");
else if(x<0)
System.out.println("The Number is Negative");
else
System.out.println("0");
}
}

Question_2
Even

or Odd Number : -

package tutorial_4;
import java.util.Scanner;
public class Q_2 {
public static void main(String[]args){
System.out.print("Enter an Integer Number= ");
Scanner input= new Scanner (System.in);
int x=input.nextInt();
if(x%2==1)
System.out.print("The Number is ODD ");
else
System.out.print("The Number is EVEN ");
}
}

Question_3
Max and Min Value : package tutorial_4;
import java.util.Scanner;
public class Q_3 {
public static void main(String[]args){
System.out.print("Enter an Integer Number= ");
Scanner input= new Scanner (System.in);
int x=input.nextInt();
System.out.print("Enter another Integer Number= ");
int y=input.nextInt();
if(x>y){
System.out.println("The Maximum Number is =

"+x );

System.out.println("The Minimum Number is =

"+y );

}
else if(x<y){
System.out.println("The Maximum Number is =

"+y );

System.out.println("The Minimum Number is =

"+x );

}
}
}

Question_3
Max and Min Value : package tutorial_4;
import javax.swing.*;
public class Q_3 {
public static void main(String[]args){
String S1= JOptionPane.showInputDialog(null,"Enter an
integer","Input",JOptionPane.QUESTION_MESSAGE);
int x = Integer.parseInt(S1);
String S2 = JOptionPane.showInputDialog(null,"Enter an
integer","Input",JOptionPane.QUESTION_MESSAGE);
int y = Integer.parseInt(S2);
if(x>y){
JOptionPane.showMessageDialog(null,"<html>The Maximum Number is =
"+x+ "<br>" +" The Minimum Number is =
"+y+"</html>","Output",JOptionPane.INFORMATION_MESSAGE);}
else if(x<y){
JOptionPane.showMessageDialog(null,"<html>The Maximum Number is =
"+y+ "<br" +" & The Minimum Number is =
"+x+"</html>","Output",JOptionPane.INFORMATION_MESSAGE);}
}
}

Question_4
Grades : package tutorial_4;
import javax.swing.*;
public class Q_4 {
public static void main(String[]args){
String C1 = JOptionPane.showInputDialog(null,"Enter your
Mark","Input",JOptionPane.QUESTION_MESSAGE);
double x = Doouble.parseDoouble (C1);
if(x>100)
JOptionPane.showMessageDialog(null,"ERROR","Output",JOptionPane.I
NFORMATION_MESSAGE);
else if(x <= 100.0 && x >= 80.0)
JOptionPane.showMessageDialog(null,"Your Grade is
A","Output",JOptionPane.INFORMATION_MESSAGE);
else if (x<=79.0 && x>=70.0)
JOptionPane.showMessageDialog(null,"Your Grade is
B","Output",JOptionPane.INFORMATION_MESSAGE);
else if (x<=69.0 && x>=50.0)
JOptionPane.showMessageDialog(null,"Your Grade is
C","Output",JOptionPane.INFORMATION_MESSAGE);
else if (x<=49.0 && x>=40.0)
JOptionPane.showMessageDialog(null,"Your Grade is
D","Output",JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(null,"Your Grade is
F","Output",JOptionPane.INFORMATION_MESSAGE);
}
}

Question_5
Grades : package tutorial_4;
import javax.swing.*;
public class Q_5 {
public static void main(String[]args){
String x= JOptionPane.showInputDialog(null,"Enter your
Grade","Input",JOptionPane.QUESTION_MESSAGE);
char[] charArray = x.toCharArray();
for (char grade : charArray){
switch (grade){
case 'a' :
JOptionPane.showMessageDialog(null,"Excellent","Output",JOptionPane.INFORMATIO
N_MESSAGE);
break;
case 'b' :
JOptionPane.showMessageDialog(null,"Good","Output",JOptionPane.INFORMATION_MES
SAGE);
break;
case 'c' :
JOptionPane.showMessageDialog(null,"Average","Output",JOptionPane.INFORMATION_
MESSAGE);
break;
case 'd' :
JOptionPane.showMessageDialog(null,"Weak","Output",JOptionPane.INFORMATION_MES
SAGE);
break;
case 'e' :
JOptionPane.showMessageDialog(null,"Very Weak","Output",JOptionPane.
INFORMATION_MESSAGE);
break;
default:
JOptionPane.showMessageDialog(null,"Invalid
Grade","Output",JOptionPane.INFORMATION_MESSAGE);
} }
} }

Вам также может понравиться