We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4
Nauman Bro Class:
public class Main {
public static void main(String[] args) { System.out.println("Allah madad farmaye."); System.out.println("this is my first program."); System.out.println("So windup now and bye."); } } --------------------------------------------------------- Chat GPT Class: import java.util.Scanner; public class Main { public static void main(String[] args) { // Create a Scanner object Scanner scanner = new Scanner(System.in);
// Prompt the user to enter an integer
System.out.print("Enter an integer: ");
// Read the integer input from the user
int number = scanner.nextInt();
// Display the input back to the user
System.out.println("You entered: " + number);
// Close the scanner to prevent resource leak
scanner.close(); } } ----------------------------------------------------- Nauman Bro Class: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner Yaqoob = new Scanner(System.in); System.out.print("enter your choice pls:"); int number = Yaqoob.nextInt(); System.out.println("Good Choice:"); } } ----------------------------------------------------- Ibrahim Bro Class:If / Else java conditions and if statements you already know that java supports the usual logical conditions from mathematics; Less than:a<b less than or equal to:a<=b greater than:a>b greater than or equal to:a>=b equal to a==b not equal to:a!=b now perform different actions for different decisions. java has following conditional statements: use if to specify a block of code to be executed, if a specified condition is true use Else to specify a block of code to be executed, if the same condition is false use else if to specify a new condition to test,if the first condition is false Use switch to specify many alternative blocks of code to be executed The if Statement Use the if statement to specify a block of java code to be executed if a condition is true. Syntax: if (condition){ //block of code to be executed if the condition is true } Note that "if" is in lowercase letters.Uppercase letters (if or IF) will generate an error. In the example below, we test two values to find out if 20 is greater than 18.if the condition is true, print some text: Example if (20>18){ System.out.println("20 is greater than 18"); } We can also test variables: Example int x=20; int y=18; if (x>y){ System.out.println("x is greater than y"); } Example explained in the example above we use two variables x and y to test whether x is greater than y (using the > operator). As x is 20, and y is 18,and we know that 20 is greater than 18, we print to the screen that "x is greater than y". ----------------------------------------------------------------------------------- ---------------Nauman Bro Class, import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner Scn=new Scanner(System.in); System.out.println("enter ur age?"); int age=Scn.nextInt(); if (age<13){ System.out.println("you are child."); }else if(age<20){ System.out.println("you are teenager."); }else if(age>20){ System.out.println("you are an adult.");} Scn.close(); } } ----------------------------------------------------------------- Nauman Bro Class, import java.util.Scanner; public class Main{ public static void main(String[] args){ int score=85; if (score>-90){ System.out.println("Grade:A");} else if (score>=80){ System.out.print("Grade:B");} else if (score>=70){ System.out.print("Grade:C"); }else if (score>=60){ System.out.println("Grade:D"); }else{ System.out.println("Grade:F");} --------------------------------------------------------------- Nauman Bro Class, import java.util.Scanner; public class Main{ public static void main(String[] args){ int age=25; if (age>=18 && age<=65){ System.out.println("The person is an adult."); }else{ System.out.println("The person is not an adult.");} --------------------------------------------------------------- Nauman Bro Class, import java.util.Scanner; public class Main{ public static void main(String[] args){ String colour="blue"; if (colour.equals("Red")){ System.out.println("The colour is red."); }else if (colour.equals("Blue")){ System.out.println("The colour is blue."); }else{ System.out.println("The colour is neither red nor blue.");} ------------------------------------------------------------------- Nauman Bro Class, import java.util.Scanner; public class Main{ public static void main(String[] args){ int number=15; if (number>0){ if (number%2==0){ System.out.println("The number is positive and even."); }else{ System.out.println("The number is positive and odd."); }else{ System.out.println("The number is not positive.");} ------------------------------------------------------------------ Nauman Bro Class, import java.util.Scanner; public class Main{ public static void main(String[] args){ int number=0; if (number>0){ System.out.println("The number is positive."); }else if (number<0){ System.out.println("The number is negative."); }else{ System.out.println("The number is zero.");} ------------------------------------------------------------------ Nauman Bro Class, import java.util.Scanner; public class Main{ public static void main(String[] args){ int number=10; if (number>0){ System.out.println("The number is positive."); }else{ System.out.println("The number not is positive.");} ------------------------------------------------------------------