| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,16 @@ | |||
| 1 | + // Write a Java program to get a number from the user and print whether it is positive or negative. | ||
| 2 | + | ||
| 3 | + import java.util.Scanner; | ||
| 4 | + | ||
| 5 | + public class Question1 { | ||
| 6 | + public static void main(String [] args){ | ||
| 7 | + Scanner sc=new Scanner(System.in); | ||
| 8 | + int num=sc.nextInt(); | ||
| 9 | + if(num>0){ | ||
| 10 | + System.out.println(num+" is positive "); | ||
| 11 | + } | ||
| 12 | + else{ | ||
| 13 | + System.out.println(num+" is negative "); | ||
| 14 | + } | ||
| 15 | + } | ||
| 16 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,12 @@ | |||
| 1 | + | ||
| 2 | + public class Question2 { | ||
| 3 | + public static void main(String args[]) { | ||
| 4 | + double temp = 103.5; | ||
| 5 | + if (temp > 100) { | ||
| 6 | + System.out.println("You have a fever"); | ||
| 7 | + } else { | ||
| 8 | + System.out.println("You have a fever"); | ||
| 9 | + } | ||
| 10 | + } | ||
| 11 | + | ||
| 12 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,35 @@ | |||
| 1 | + // Write a Java program to input week number (1-7) and print day of week name using switch case. | ||
| 2 | + import java.util.*; | ||
| 3 | + public class Question3 { | ||
| 4 | + public static void main(String args[]){ | ||
| 5 | + Scanner sc= new Scanner(System.in); | ||
| 6 | + int num=sc.nextInt(); | ||
| 7 | + switch (num) { | ||
| 8 | + case 1: | ||
| 9 | + System.out.println("Monday"); | ||
| 10 | + break; | ||
| 11 | + case 2: | ||
| 12 | + System.out.println("Tuesday"); | ||
| 13 | + break; | ||
| 14 | + case 3: | ||
| 15 | + System.out.println("Wednessday"); | ||
| 16 | + break; | ||
| 17 | + case 4: | ||
| 18 | + System.out.println("Thursday"); | ||
| 19 | + break; | ||
| 20 | + case 5: | ||
| 21 | + System.out.println("Friday"); | ||
| 22 | + break; | ||
| 23 | + case 6: | ||
| 24 | + System.out.println("Saturaday"); | ||
| 25 | + break; | ||
| 26 | + case 7: | ||
| 27 | + System.out.println("Sunday"); | ||
| 28 | + break; | ||
| 29 | + | ||
| 30 | + default: | ||
| 31 | + System.out.println("Wrong Input"); | ||
| 32 | + break; | ||
| 33 | + } | ||
| 34 | + } | ||
| 35 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,21 @@ | |||
| 1 | + // Write a Java program that takes a year from the user and print whether that year is a leap year or not. | ||
| 2 | + | ||
| 3 | + import java.util.*; | ||
| 4 | + | ||
| 5 | + public class Question5 { | ||
| 6 | + public static void main(String args[]){ | ||
| 7 | + Scanner sc=new Scanner(System.in); | ||
| 8 | + int year=sc.nextInt(); | ||
| 9 | + | ||
| 10 | + if(year%4==0){ | ||
| 11 | + if(year%100==0){ | ||
| 12 | + if(year%400==0){ | ||
| 13 | + System.out.println("leap year"); | ||
| 14 | + } | ||
| 15 | + else{ | ||
| 16 | + System.out.println("Not a leap year"); | ||
| 17 | + } | ||
| 18 | + } | ||
| 19 | + } | ||
| 20 | + } | ||
| 21 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments