Task - Control Flow Statements - Conditional Statements - Decision Making Statements - if-else statement #82
Replies: 46 comments
-
1import java.util.Scanner;
class If1{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Length: ");
int length=Integer.parseInt(sc.next());
System.out.println("Breadth: ");
int breadth=Integer.parseInt(sc.next());
if (length==breadth) {
System.out.println("The Rectangle is square");
}
else{
System.out.println("It is Rectangle");
}
sc.close();
}
}2import java.util.Scanner;
public class If2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("A: ");
int a=Integer.parseInt(sc.next());
System.out.println("B: ");
int b=Integer.parseInt(sc.next());
if (a>b) {
System.out.println("A is Greater than B");
}
else{
System.out.println("B is Greater than A");
}
sc.close();
}
}3import java.util.Scanner;
public class If3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the quantity:");
int quantity = Integer.parseInt(sc.next());
int discount = 0;
if(quantity >1000){
discount=(quantity*10)/100;
System.out.println(discount);
System.out.println("Total amount"+(quantity+discount));
}
sc.close();
}
}4import java.security.Provider.Service;
import java.util.Scanner;
/*A company decided to give a bonus of 5% to the employee if his/her year of service is more than 5 years.
Ask the user for their salary and year of service and print the net bonus amount. */
public class If4 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the salary ");
int salary = Integer.parseInt(sc.next());
System.out.println("Enter the year of service ");
int service = Integer.parseInt(sc.next());
int bonus=0;
if (service > 5){
bonus=(salary*5)/100;
System.out.println("Net bonus "+bonus);
}
sc.close();
}
}5import java.util.Scanner;
/*Write a program to print the absolute value of a number entered by the user.
E.g.-
INPUT: 1 OUTPUT: 1
INPUT: -1 OUTPUT: 1 */
public class If5 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the input number");
int input = Integer.parseInt(sc.next());
int output=0;
if (input > 0)
{
output= 1 * input;
}
System.out.println(output);
}
}6import java.util.Scanner;
public class If7 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of classes held");
int noOfClasses = Integer.parseInt(sc.next());
System.out.println("Enter the number of classes attended");
int noOfClassesAttended = Integer.parseInt(sc.next());
int percentage=((noOfClassesAttended*100)/noOfClasses);
if(percentage>75)
System.out.println("The student is allowed to sit in the exam");
else{
System.out.println("The student will not be allowed to sit in the exam");
}
sc.close();
}
}7import java.util.Scanner;
public class If8 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of classes held");
int noOfClasses = Integer.parseInt(sc.next());
System.out.println("Enter the number of classes attended");
int noOfClassesAttended = Integer.parseInt(sc.next());
int percentage=((noOfClassesAttended*100)/noOfClasses);
System.out.println("Enter ('Y'/'N') for medical cause:");
int medicalCause=sc.next().charAt(0);
if(percentage>75)
System.out.println("The student is allowed to sit in the exam");
else if (percentage<75 && medicalCause=='Y' ){
System.out.println("THe student is allowed to sit in the exam");
}
else{
System.out.println("The student will not be allowed to sit in the exam");
}
sc.close();
}
}
|
Beta Was this translation helpful? Give feedback.
-
Problem 1 - CheckSquarepackage ControlFlowStatement;
import java.util.Scanner;
public class IfElseProblem1{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter the length of the rectangle: ");
float length=sc.nextFloat();
System.out.print("Enter the breadth of the rectangle: ");
float breadth=sc.nextFloat();
if(length==breadth){
System.out.println("It's a Square");
}
else{
System.out.println("It's a Rectangle");
}
sc.close();
}
}Problem 2 - GreatestNumberpackage ControlFlowStatement;
import java.util.Scanner;
public class IfElseProblem2 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter two values: ");
int val1=sc.nextInt();
int val2=sc.nextInt();
if(val1>val2){
System.out.println(val1+" is greater than "+val2);
}
else{
System.out.println(val2+" is greater than "+val1);
}
sc.close();
}
}Problem 3 - CostWithDiscountpackage ControlFlowStatement;
import java.util.Scanner;
public class IfElseProblem3 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the quantity: ");
double quantity=sc.nextDouble();
double cost=quantity*100;
if(cost>1000){
cost-=cost*0.1;
}
System.out.println("total cost for user: "+cost);
}
}Problem 4 - CompanySalarypackage ControlFlowStatement;
import java.util.Scanner;
public class IfElseProblem4 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter the salary for employee: ");
double salary = sc.nextDouble();
System.out.print("Enter the year of serive(in years) for employee: ");
double yearOfSerive = sc.nextDouble();;
double bonus=0.05;
if(yearOfSerive>5){
salary+=salary*bonus;
}
System.out.println("The Net Salary is: "+salary);
sc.close();
}
}Problem 5 - AbsoluteValuepackage ControlFlowStatement;
import java.util.Scanner;
public class IfElseProblem5 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter a Number: ");
double number=sc.nextDouble();
if(number>0) {
System.out.println("The number entered by user is: "+number);
}
else{
System.out.println("The number entered by user is: "+Math.abs(number));
}
sc.close();
}
}Problem 6 - CheckUppercaseOrLowercasepackage ControlFlowStatement;
import java.util.Scanner;
public class IfElseProblem6 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter a character:");
char character=sc.next().charAt(0);
if(character>=65 && character<=90){
System.out.println("The character is in UpperCase");
}
if(character>=97 && character<=122){
System.out.println("The character is in LowerCase");
}
sc.close();
}
}Problem 7 - StudentAttendancepackage ControlFlowStatement;
import java.util.Scanner;
public class IfElseProblem7 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of classes held: ");
int classHeld=Integer.parseInt(sc.nextLine());
System.out.println("Enter the number of classes attended: ");
int classAttended=Integer.parseInt(sc.nextLine());
int classPercentage=(classAttended*100)/classHeld;
int StandardAttendance=75;
if(classPercentage>StandardAttendance){
System.out.println("The Student is allowed to sit in exam.");
}
else{
System.out.println("The Student is not allowed to sit in the exam.");
}
sc.close();
}
}
Problem 8 - StudentMedicalCausepackage ControlFlowStatement;
import java.util.Scanner;
public class IfElseProblem7 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of classes held: ");
int classHeld=Integer.parseInt(sc.nextLine());
System.out.println("Enter the number of classes attended: ");
int classAttended=Integer.parseInt(sc.nextLine());
System.out.println("Enter if you have a Medical Cause(Y or N): ");
char medicalCause=sc.next().charAt(0);
int classPercentage=(classAttended*100)/classHeld;
int StandardAttendance=75;
if(classPercentage>StandardAttendance && medicalCause=='Y'|| medicalCause=='y'){
System.out.println("The Student is allowed to sit in exam.");
}
else{
System.out.println("The Student is not allowed to sit in the exam.");
}
sc.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
1import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner obj=new Scanner(System.in);
System.out.println("Enter the length:");
int length=obj.nextInt();
System.out.println("Enter the breadth:");
int breadth=obj.nextInt();
if(length==breadth)
{
System.out.println("it is square");
}
else{
System.out.println("it is a rectangle");
}
}
}2import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner obj=new Scanner(System.in);
System.out.println("Enter the number one:");
int numberOne=obj.nextInt();
System.out.println("Enter the number two:");
int numberTwo=obj.nextInt();
if(numberOne > numberTwo)
{
System.out.println(numberOne+" is greater number");
}
else{
System.out.println(numberTwo+" is greater number");
}
}
}3import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner obj=new Scanner(System.in);
System.out.println("Enter the quantity of the product:");
int quantity=obj.nextInt();
System.out.println("Enter the cost of product:");
int costPrice=obj.nextInt();
int totalPrice=quantity*costPrice;
if(totalPrice>1000)
{
int discountPrice=(totalPrice*10)/100;
System.out.println("total cost is:"+(totalPrice-discountPrice));
}
else{
System.out.println("total cost is:"+totalPrice);
}
}
}4import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner obj=new Scanner(System.in);
System.out.println("Enter your salary:");
int salary=obj.nextInt();
System.out.println("Enter your experience:");
float experience=obj.nextInt();
if(experience>5)
{
double bonus=((salary*5)/100);
System.out.println("your bonum amount is:"+bonus);
}
else{
System.out.println("you are not eligible for this bonus");
}
}
}5import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner obj=new Scanner(System.in);
System.out.println("Enter the number:");
int number=obj.nextInt();
if(number>0)
{
System.out.println("the number is: "+number);
}else{
System.out.println("the number is: "+Math.abs(number));
}
}
}6import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner obj=new Scanner(System.in);
System.out.println("Enter the character:");
char character=obj.next().charAt(0);
if(character>=65&&character<=90)
{
System.out.println("the character is upper case");
}else
{
System.out.println("the character is not upper case");
}
if(character>=97&&character<=122){
System.out.println("the character is lower case");
}else
{
System.out.println("the character is not lower case");
}
}
}7,8import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner obj=new Scanner(System.in);
System.out.println("Enter the no of classes held:");
int noOfClassesHeld=obj.nextInt();
System.out.println("Enter the no of classes student attended :");
int noOfClassesAttended=obj.nextInt();
System.out.println("medical cause:");
String medicalCause=obj.next();
int percentage=((noOfClassesAttended*100)/noOfClassesHeld);
System.out.println("percentage :"+percentage);
if(percentage>75 && !medicalCause.equalsIgnoreCase("Y"))
{
System.out.println("the student allowed in the exam ");
}else{
System.out.println("the student not allowed in the exam ");
}
obj.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
1import java.util.Scanner;
public class Ques1 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter length and breadth of a rectangle");
int len=sc.nextInt();
int bre=sc.nextInt();
if(len==bre){
System.out.println("It is a Square");
}
else{
System.out.println("It is a Rectangle");
}
sc.close();
}
}2import java.util.Scanner;
public class Ques2 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter two numbers::");
int num1=sc.nextInt();
int num2=sc.nextInt();
if(num1>num2){
System.out.println(num1+" is greater");
}
else{
System.out.println(num2+" is greater");
}
sc.close();
}
}3import java.util.Scanner;
public class Ques3 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the quantity");
int qnty=sc.nextInt();
int unit=100;
int total=unit*qnty;
if(qnty>10){
total-=(total/10);
}
System.out.println("Total cost:"+total);
sc.close();
}
}4import java.util.Scanner;
public class Ques4 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Salary , and the year of service:");
int sal=sc.nextInt();
int year=sc.nextInt();
if(year>5){
sal+=(sal*0.05);
}
System.out.println("Total salary:"+sal);
sc.close();
}
}5import java.util.Scanner;
public class Ques5 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number");
int num=sc.nextInt();
if(num<0){
num*=-1;
}
System.out.println("Absolute value::"+num);
}
}6 import java.util.Scanner;
public class Ques6 {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
System.out.print("Enter a character:");
char ch=sc.next().charAt(0);
if(ch>64 && ch<91){
System.out.println("UpperCase character");
}
if(ch>96 && ch<123){
System.out.println("Lowercase character");
}
else {
System.out.println(" Invalid character");
}
sc.close();
}
}7,8import java.util.Scanner;
public class Ques7 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number of classes:");
int numofclass=sc.nextInt();
System.out.println("Enter the number of classes Attended:");
int numclsatt=sc.nextInt();
System.out.println("Enter the Medical Cause('Y' Or 'N'):");
char medical=sc.next().charAt(0);
int percent=(numclsatt*100/numofclass);
if(percent>75 || medical=='Y'){
System.out.println("Allowed to Attend Exam");
}
else{
System.out.println("Not Allowed");
}
sc.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
1import java.util.Scanner;
public class SqOrNot {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter length and breadth values");
int l = Integer.parseInt(sc.nextLine());
int b = Integer.parseInt(sc.nextLine());
if (l == b) {
System.out.println("Square");
} else {
System.out.println("Rectangle");
}
sc.close();
}
}2import java.util.Scanner;
public class Great {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter two integer values");
int a = Integer.parseInt(sc.nextLine());
int b = Integer.parseInt(sc.nextLine());
if (a > b) {
System.out.println(String.format("number %d is greater than %d", a, b));
} else {
System.out.println(String.format("number %d is greater than %d", b, a));
}
sc.close();
}
}3import java.util.Scanner;
public class Shop {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter quantity");
int q = Integer.parseInt(sc.nextLine());
int cost = q * 100;
double totcost = 0;
if (cost > 1000) {
totcost = cost - (cost * 0.1);
} else {
totcost = cost;
}
System.out.println("Total cost is: " + totcost);
sc.close();
}
}4import java.util.Scanner;
public class Bonus {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter rour salary");
int sal = Integer.parseInt(sc.nextLine());
System.out.println("Enter year of service");
int years = Integer.parseInt(sc.nextLine());
double bonus;
if (years > 5) {
bonus = sal * 0.05;
} else {
bonus = 0;
}
System.out.println("Your net bonus amount is " + (sal + bonus));
sc.close();
}
}5import java.util.Scanner;
public class AbsoluteValue {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a Number: ");
int number = sc.nextInt();
if (number > 0) {
System.out.println("The number entered by user is: " + number);
} else {
System.out.println("The number entered by user is: " + Math.abs(number));
}
sc.close();
}
}
```
### 6
```java
import java.util.Scanner;
public class LowOrUppCase {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a character:");
char c = sc.next().charAt(0);
if (c >= 65 && c <= 90) {
System.out.println("The character is in UpperCase");
}
if (c >= 97 && c <= 122) {
System.out.println("The character is in LowerCase");
}
sc.close();
}
}
```
### 7,8
```java
import java.util.Scanner;
public class Exam2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter number of classes held:");
double c = Integer.parseInt(sc.nextLine());
System.out.println("Number of classes attended:");
double at = Integer.parseInt(sc.nextLine());
double per = (at / c) * 100;
System.out.println(String.format("Percentage of classes attended: %.2f", per));
System.out.println("Do you have any medical cause? ('Y'or'N')");
char ch = sc.next().charAt(0);
if (per > 75 && ch == 'N') {
System.out.println("Student will be allowed to sit in an exam");
} else {
System.out.println("Student will not be allowed to sit in an exam");
}
sc.close();
}
}
``` |
Beta Was this translation helpful? Give feedback.
-
1.Take values of the length and breadth of a rectangle from the user and check if it is square or not.package Operators.ControlFlow;
import java.util.Scanner;
public class IfSquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the length:");
int l=Integer.parseInt(sc.nextLine());
System.out.println("Enter the breadth:");
int b=Integer.parseInt(sc.nextLine());
if(l==b){
System.out.println("It is a Square!!!");
}
else{
System.out.println("It is a Resctangle...");
}
sc.close();
}
}2.Take two int values from the user and print the greatest among them.package Operators.ControlFlow;
import java.util.Scanner;
public class Greater {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the value of a:");
int a=Integer.parseInt(sc.nextLine());
System.out.println("Enter the value of b:");
int b=Integer.parseInt(sc.nextLine());
if(a>b){
System.out.println("a is greater than b");
}
else{
System.out.println("b is greater than a");
}
sc.close();
}
}3.Discountpackage Operators.ControlFlow;
import java.util.Scanner;
public class Discount {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the quantity: ");
int qty=Integer.parseInt(sc.nextLine());
double cost=qty*100;
if(cost>1000){
cost-=cost*0.1;
System.out.println("The cost is: "+cost);
}
else{
System.out.println("No discount....");
}
sc.close();
}
}4.Bonuspackage Operators.ControlFlow;
import java.util.Scanner;
public class Bonus {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
double bonus=0;
System.out.println("Enter the salary:");
double sal=Integer.parseInt(sc.nextLine());
System.out.println("Enter the year of service: ");
int serv=Integer.parseInt(sc.nextLine());
if(serv>5){
bonus=sal+sal*0.05;
System.out.println("The bonus is: "+bonus);
}
else{
System.out.println("No bonus...");
}
sc.close();
}
}5.Absolutepackage Operators.ControlFlow;
import java.util.Scanner;
public class Discount {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the quantity: ");
int qty=Integer.parseInt(sc.nextLine());
double cost=qty*100;
if(cost>1000){
cost-=cost*0.1;
System.out.println("The cost is: "+cost);
}
else{
System.out.println("No discount....");
}
sc.close();
}
}6.ASCIIpackage Operators.ControlFlow;
import java.util.Scanner;
public class Ascii {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the character:");
char a=sc.nextLine().charAt(0);
if(a>=65 && a<=90){
System.out.println("It is a Upper case");
}
if(a>=97 && a<=122){
System.out.println("It is a lower case");
}
else{
System.out.println("Not an alphabet...");
}
sc.close();
}
}7.Attendancepackage Operators.ControlFlow;
import java.util.Scanner;
public class Attendance {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of classes held: ");
int ch=Integer.parseInt(sc.nextLine());
System.out.println("Enter the number of classes attended: ");
int ca=Integer.parseInt(sc.nextLine());
int per=(ca*100)/ch;
System.out.println("The percentage is: "+per);
if(per>75){
System.out.println("Allowed to sit in exam !!!");
}
else{
System.out.println("Not Allowed...");
}
sc.close();
}
}8.MedicalCausepackage Operators.ControlFlow;
import java.util.Scanner;
public class Attendance {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of classes held: ");
int ch=Integer.parseInt(sc.nextLine());
System.out.println("Enter the number of classes attended: ");
int ca=Integer.parseInt(sc.nextLine());
System.out.println("Enter ('Y'/'N') for medical cause:");
int medicalCause=sc.nextLine().charAt(0);
int per=(ca*100)/ch;
System.out.println("The percentage is: "+per);
if(per>75 || medicalCause=='Y'){
System.out.println("Allowed to sit in exam !!!");
}
else{
System.out.println("Not Allowed...");
}
sc.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
Decision Making Statements1.Squarepackage module.decision;
import java.util.Scanner;
public class CheckSquare {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the length");
int length=sc.nextInt();
System.out.println("Enter the breadth");
int breadth=sc.nextInt();
if(length==breadth)
System.out.println("Square");
else
System.out.println("not a sqaure");
}}2 Greatestpackage module.decision;
import java.util.Scanner;
public class Greaterdemo {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the first number");
int num1=sc.nextInt();
System.out.println("Enter the second number");
int num2=sc.nextInt();
if(num1>num2)
System.out.println(num1+" is the greatest number");
else
System.out.println(num2+ " is the greatest number");
}
}3 Quantitypackage module;
import java.util.Scanner;
public class QuantityDemo {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Quantity");
int quantity=sc.nextInt();
int cost=quantity*100;float totalcost;
if(cost>1000)
totalcost=(cost-((cost*10)/100));
else
totalcost=cost;
System.out.println("the totalcost is "+totalcost);
}
}4 Netbounspublic class SalaryBonus {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the salary ");
int salary=sc.nextInt();
System.out.println("Enter the year of service ");
int yearofexp=sc.nextInt();
if(yearofexp>5)
salary+=(salary/20);
System.out.println("net bonus amount is " + salary);
}
}5 Absolutepackage module.decision;
import java.util.Scanner;
public class AbsoluteValue {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the value");
int val=sc.nextInt();
if(val>0)
System.out.println("output: " + val);
else
System.out.println("output: " + val*-1);
}
}6. Check Casepackage module.decision;
import java.util.Scanner;
public class CaseCheck {
public static void main(String[] args) throws Exception {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Character ");
char ch=sc.next().charAt(0);
if(ch>=65 && ch<=90)
System.out.println("the given character is uppercase");
if(ch>=97 && ch<=122)
System.out.println("the given character is lowercase");
else
System.out.println("Not a valid character");
}
}7package module.decision;
import java.util.Scanner;
public class AttendanceDemo {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of classes held ");
int numclassheld =sc.nextInt();
System.out.println("Enter the number of classes attended ");
int numclassattend =sc.nextInt();
System.out.println("Number of classes attended is " + numclassattend);
float percentage=((numclassattend*100)/numclassheld);
if(percentage>=75 )
System.out.println(" eligible to attend exam ");
else
System.out.println(" not eligible to attend exam");
}
}8package module.decision;
import java.util.Scanner;
public class AttendanceProgm {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of classes held ");
int numclassheld =sc.nextInt();
System.out.println("Enter the number of classes attended ");
int numclassattend =sc.nextInt();
System.out.println("Number of classes attended is " + numclassattend);
System.out.println("Enter the medical clause (Y/N) ");
char medical =sc.next().charAt(0);
float percentage=((numclassattend*100)/numclassheld);
if(percentage>=75 || medical=='Y')
System.out.println(" eligible to attend exam ");
else
System.out.println(" not eligible to attend exam");
}
} |
Beta Was this translation helpful? Give feedback.
-
1 Squareimport java.util.*;
public class RecSq{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter length : ");
int length = sc. nextInt();
System.out.println("Enter breadth : ");
int breadth = sc.nextInt();
if(length == breadth)
System.out.println("It is s square...");
else
System.out.println("It is a rectangle...");
}
}2 Greatest numberimport java.util.*;
public class Greatest{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter a : ");
int a = sc.nextInt();
System.out.println("Enter b : ");
int b = sc.nextInt();
if(a>b)
System.out.println("a is greater than b");
else
System.out.println("b is greater than a");
}
}3 Shopimport java.util.*;
public class ShopDiscount{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter quantity : ");
int quantity = sc.nextInt();
int cost = 100, total;
total = quantity * cost;
if(quantity > 10){
total -= (total/10);
}
System.out.println("Amount : "+total);
}
}4import java.util.*;
public class Bonus{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter salary: ");
float salary = sc.nextFloat();
System.out.println("Enter year of service: ");
float year = sc.nextFloat();
if(year > 5){
salary+=(salary/20);
}
System.out.println("Bonus salary: "+salary);
}
}5import mport java.util.*;
public class AbsoluteNum{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("Enter number : ");
int num = scanner.nextInt();
if(num<0){
num = num*(-1);
}
System.out.println("Absolute number : "+num);
}
}6import java.util.*;
public class LowUp{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the character:");
char a = scanner.nextLine().charAt(0);
if(a>=65 && a<=90){
System.out.println("Upper Case...");
}
else{
System.out.println("Lower case...");
}
}
}7import java.util.*;
public class Attendance{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter Number of classes held : ");
int a = sc.nextInt();
System.out.println("Enter Number of classess attended : ");
int b = sc.nextInt();
int percentage = (b*100)/a;
System.out.println("Percentage : "+percentage);
if(c>75){
System.out.println("Allowed to sit in exam...");
}
else{
System.out.println("Not Allowed to sit in exam");
}
}
}8import java.util.*;
public class Attendance{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter Number of classes held : ");
int a = sc.nextInt();
System.out.println("Enter Number of classess attended : ");
int b = sc.nextInt();
System.out.println("Enter ('Y'/'N') for medical cause : ");
char medical = sc.next().charAt(0);
int percentage = (b*100)/a;
System.out.println("Percentage : "+percentage);
if(percentage>75 && medical=='Y'){
System.out.println("Allowed to sit in exam...");
}
else{
System.out.println("Not Allowed to sit in exam");
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Squarepublic class Rectangle {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the value of length ::");
int len = sc.nextInt();
System.out.println("Enter the value of breadth ::");
int breadth = sc.nextInt();
if (len == breadth) {
System.out.println("The given dimensions are Square!");
} else {
System.out.println("The given dimensions are not a Square!");
}
}
}Greater Numberpublic class GreaterNum {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number num1 :: ");
int num1 = sc.nextInt();
System.out.println("Enter a number num2 :: ");
int num2 = sc.nextInt();
if (num1 > num2)
System.out.println("Num1 is Greater");
else
System.out.println("Num2 is Greater");
}
}TotalCostpublic class Discount {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the quantity :: ");
int quantity = sc.nextInt();
System.out.println("Enter the unitCost Amount :: ");
int unitCost = sc.nextInt();
int totalCost = quantity * unitCost;
if (totalCost >= 1000) {
int discount = ((totalCost) * 10/100);
System.out.println("The total cost is " + discount);
} else {
System.out.println("The total cost is " + totalCost);
}
}
}Net Salarypublic class NetSalary {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter your Salary ::");
int salary = sc.nextInt();
System.out.println("Enter your Service years ::");
int serviceYears = sc.nextInt();
if (serviceYears > 5) {
int netSalary = ((salary) * 5/100);
System.out.println("Your Net Salary is " + netSalary);
}
}
}Absolute Numberpublic class AbsoluteNum {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number :: ");
int n = sc.nextInt();
if (n > 0)
System.out.println("The absolute number is :: " + Math.abs(n));
}
}ASCIIpublic class UpperOrLowerCase {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the character :: ");
char c = sc.next().charAt(0);
if (c >= 65 && c <= 90)
System.out.println("The Given Character is UpperCase");
else
System.out.println("The Given Character is LowerCase");
}
}Attendance & Medical Causepublic class Attendance {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the No.of Classes Held:");
int clsHeld = sc.nextInt();
System.out.println("Enter the No.of Classes attended :");
int ClsAttended = sc.nextInt();
System.out.println("He/She has a Medical cause (Yes or No):");
String medicalCause=sc.next();
int percent = ((ClsAttended*100)/clsHeld);
if(percent>75 || medicalCause.equalsIgnoreCase("Yes"))
System.out.println("Student is allowed to sit in the exam");
else
System.out.println("Student is not allowed to sit in the exam");
}
} |
Beta Was this translation helpful? Give feedback.
-
1import java.util.Scanner;
public class Rectangle {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Rectangle length:");
double length=sc.nextDouble();
System.out.println("Enter the Rectangle breath:");
double breath=sc.nextDouble();
if(length==breath){
System.out.println("It is Square");
}
else{
System.out.println("It is Rectangle");
}
}
}2import java.util.Scanner;
public class Greater {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the value of a:");
int a=sc.nextInt();
System.out.println("Enter the value of b:");
int b=sc.nextInt();
if(a>b){
System.out.println("a is greater than b");
}
else{
System.out.println("b is greater than a");
}
}
}3import java.util.Scanner;
public class TotalCost {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the quantity :");
int quantity = scanner.nextInt();
if(quantity>1000){
System.out.println("you have 10% discount");
int Discount=(quantity*10)/100;
int TotalCost=quantity-Discount;
System.out.println("Your total cost is " + TotalCost);
}else{
System.out.println("You have no discout and your total cost is " + quantity);
}
}
}4import java.util.Scanner;
public class NetBonus {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the salary:");
int salary =sc.nextInt();
System.out.println("Enter the Year of Experience:");
int year =sc.nextInt();
if (year>5){
System.out.println("You have 5% Bonus");
int bonus=(salary*5)/100;
System.out.println("Bonus: " + bonus);
int total=bonus+salary;
System.out.println("your Total salary is: " + total);
}else{
System.out.println("you dont have any bonus");
}
}
}5import java.util.Scanner;
public class Absolute {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter any number");
int num=sc.nextInt();
if(num>0){
System.out.println("The Absolute number is " + num);
}
else{
System.out.println("The Absolute number is:"+Math.abs(num));
}
}
}6import java.util.Scanner;
public class Alphabet {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter any alphabetic");
char Alphabet=sc.next().charAt(0);
if( Alphabet>=65 && Alphabet<=90){
System.out.println("The alphabet is Uppercase");
}
else if(Alphabet>=97 && Alphabet<=122){
System.out.println("The alphabet is Lowercase");
}
}
}7,8import java.util.Scanner;
public class Attendence {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Is the student has medical cause?(Y/N)");
String medicalCause=sc.next();
System.out.println("Enter the number of classes held:");
int held=sc.nextInt();
System.out.println("Enter the number of classes attended:");
int present=sc.nextInt();
int Attendence=(present*100)/held;
System.out.println("attendence"+Attendence);
if(Attendence>75 && medicalCause.equals("N")){
System.out.println("The student is allowed to sit");
}
else{
System.out.println("The student is not allowed to sit");
}
}
}
|
Beta Was this translation helpful? Give feedback.
-
1.cf1.javaimport java.util.*;
public class cf1 {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the length: ");
int length=Integer.parseInt(sc.nextLine());
System.out.print("Enter the breadth: ");
int breadth=Integer.parseInt(sc.nextLine());
if(length==breadth)
System.out.println("Is a square");
else
System.out.println("Not a square it is a Rectangle");
sc.close();
}
}Output2.cf2.javaimport java.util.Scanner;
public class Cf2 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter the value of a: ");
int a=Integer.parseInt(sc.nextLine());
System.out.print("Enter the value of b: ");
int b=Integer.parseInt(sc.nextLine());
if(a>b)
System.out.println(String.format("%d is greater",a));
else
System.out.println(String.format("%d is greater",b));
sc.close();
}
}Output3.cf3.javaimport java.util.Scanner;
public class cf3 {
public static void main(String[] args)
{
double unit;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the quantity: ");
int qty=Integer.parseInt(sc.nextLine());
System.out.print("Enter the unit price: ");
unit=Integer.parseInt(sc.nextLine());
Double price=unit*qty;
if(qty>1000)
{
System.out.println("Got an discount");
price=price-((price*10)/100);
}
else
System.out.println("Less than the required quantity for the discount");
System.out.println(String.format("Total cost= %.2f",price));
sc.close();
}
}Output4.cf4.javaimport java.util.Scanner;
public class cf4 {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the salary: ");
double sal=Double.parseDouble(sc.nextLine());
System.out.print("Year of service: ");
double exp=Double.parseDouble(sc.nextLine());
if(exp>5)
{
sal=sal+((sal*5)/100);
System.out.println(String.format("Congrats you have got an Increment!!\nTotal salary=%.2f",sal));
}
else
System.out.println(String.format("Not enough Experience\nTotal salary=%.2f",sal));
sc.close();
}
}Output5cf5.javaimport java.util.Scanner;
public class cf5 {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number: ");
int num=Integer.parseInt(sc.nextLine());
if(num<0)
num=-(num);
System.out.println(num);
sc.close();
}
}Output6.cf6.javaOutput7.cf7.javaimport java.util.Scanner;
public class cf7 {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number of classes held: ");
int clas=Integer.parseInt(sc.nextLine());
System.out.print("Enter the number of classes attended: ");
int atten=Integer.parseInt(sc.nextLine());
double att=(atten*100)/100;
System.out.println(String.format("Percentage of classes attended: %.2f",att));
if(att<75)
System.out.println("Attendance low \nnot Allowed to sit");
else
System.out.println("Attendance is of the range \nAllowed to sit");
sc.close();
}
}Output8.cf8.javaimport java.util.Scanner;
public class cf8 {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number of classes held: ");
int clas=Integer.parseInt(sc.nextLine());
System.out.print("Enter the number of classes attended: ");
int atten=Integer.parseInt(sc.nextLine());
double att=(atten*100)/100;
System.out.println(String.format("Percentage of classes attended: %.2f",att));
System.out.print("Any Medical cause? :");
char cause=sc.nextLine().charAt(0);
if(cause=='y'||cause=='Y')
{
if(att<75)
System.out.println("Attendance low \nnot Allowed to sit");
else
System.out.println("Attendance is of the range \nAllowed to sit");
}
else if(cause=='n'||cause=='N')
System.out.println("not Allowed to sit");
sc.close();
}
}Output |
Beta Was this translation helpful? Give feedback.
-
1import java.util.*;
public class CheckSquare {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the length");
int length=sc.nextInt();
System.out.println("Enter the breadth");
int breadth=sc.nextInt();
sc.close();
if(length==breadth)
{
System.out.println("It is square");
}
else
{
System.out.println("It is not a square");
}
}
}2import java.util.*;
public class GreatestNumber {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter two numbers");
int num1=sc.nextInt();
int num2=sc.nextInt();
if(num1>num2)
{
System.out.println("num1 is greater");
}
else
{
System.out.println("num2 is greater");
}
}
}3import java.util.*;
public class ShopDiscount {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter quantity");
int quantity=sc.nextInt();
float totalcost;
sc.close();
if(quantity*100>1000)
{
totalcost= ((quantity*100)-((10*(quantity*100)/100)));
}
else
{
totalcost=quantity*100;
}
System.out.println("The total cost is " +totalcost);
}
}4import java.util.Scanner;
public class Bonus {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter your salary:");
int salary =sc.nextInt();
System.out.println("Enter year of service:");
int service =sc.nextInt();
if (service>5){
int bonus=(salary*5)/100;
System.out.println("Bonus: " + bonus);
int total=bonus+salary;
System.out.println("Total salary is: " + total);
}
else{
System.out.println("Not eligible for bonus");
}
}
}5import java.util.Scanner;
public class AbsoluteExample {
public static void main(String[] args)
{
System.out.println("Enter a number: ");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
sc.close();
System.out.println(Math.abs(n));
}
}
|
Beta Was this translation helpful? Give feedback.
-
1 public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter length");
int length=scanner.nextInt();
System.out.println("Enter Breadth");
int breadth=scanner.nextInt();
if(length==breadth)
{
System.out.println("Given Rectangle is a square");
}
else{
System.out.println("Given Rectangle is NOT a square");
}
scanner.close();
}
}2public class GreatestNumber {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter num1");
int num1=scanner.nextInt();
System.out.println("Enter num2");
int num2=scanner.nextInt();
if(num1>num2)
{
System.out.println("Greatest number is "+num1);
}
if(num2>num1)
{
System.out.println("Greatest number is "+num2);
}
if(num1==num2)
{
System.out.println("Both numbers are Equal");
}
scanner.close();
}
}3public class ShopCost {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter quantity");
int num1=scanner.nextInt();
int cost=100;
int costTotal=num1*cost;
if(costTotal > 1000)
{
int costTotalReduced=(costTotal*10)/100;
costTotal=costTotal-costTotalReduced;
System.out.println("Cost after discount applied "+costTotal);
}
else{
System.out.println("Cost without discount applied "+costTotal);
}
scanner.close();
}
}4public class EmployeeBonus {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter Salary");
int salary=scanner.nextInt();
System.out.println("Enter Service");
int service=scanner.nextInt();
int bonusSalary=0;
if(service>=5)
{
bonusSalary=salary+(salary*5/100);
System.out.println("Salary after bonus "+bonusSalary);
}
else{
System.out.println("Salary without bonus "+salary);
}
scanner.close();
}
}5public class AbsoluteNumber {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter Number");
int number=scanner.nextInt();
if(number<0)
{
System.out.printf("Absolute Number is %d",(number*(-1)));
}
else{
System.out.printf("Absolute Number is %d",number);
}
scanner.close();
}
}6public class Ascii {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter character");
char ch=scanner.next().charAt(0);
int value=(int)ch;
if(value>=97 && value<=122)
{
System.out.println("Character is LOWER CASE ");
}
if(value>=65 && value<=90)
{
System.out.println("Character is UPPER CASE ");
}
scanner.close();
}
}7,8 public class Attendance {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter Class held");
int totalClass=Integer.parseInt(scanner.nextLine());
System.out.println("Enter Class attended");
int classAttended=Integer.parseInt(scanner.nextLine());
System.out.println("Enter you have medical issue or not");
String health=scanner.nextLine();
double percentage=(double)(classAttended*100)/totalClass;
System.out.println("Percentage of Class attended "+percentage);
if(percentage>75 && !health.equalsIgnoreCase("Y"))
{
System.out.println("ALLOWED to sit in exam...");
}
else{
System.out.println("NOT ALLOWED to sit in exam...");
}
scanner.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
TASK-CONTROL FLOW STATEMENTS-DECISION MAKING STATEMENTS1.Take values of the length and breadth of a rectangle from the user and check if it is square or not.LengthSquare.javaimport java.util.Scanner;
public class LengthSquare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("ENTER LENGTH:");
int l=Integer.parseInt(sc.nextLine());
System.out.println("ENTER BREADTH:");
int b=Integer.parseInt(sc.nextLine());
if(l==b)
System.out.println("IT IS A SQUARE");
else
System.out.println("IT IS A RECTANGLE");
}
}2.Take two int values from the user and print the greatest among them.LargestDemo.java import java.util.Scanner;
public class LargestDemo {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("ENTER THE NUM-1:");
int num1=sc.nextInt();
System.out.println("ENTER THE NUM-2:");
int num2=sc.nextInt();
if(num1>num2)
{
System.out.println(num1+" "+"IS THE GREATEST NUMBER");
}
else
{
System.out.println(num2+" "+"IS THE GREATEST NUMBER");
}
}
}3.A shop will give a discount of 10% if the cost of the purchased quantity is more than 1000.Ask the user for the quantity. PurchaseDemo.javaimport java.util.Scanner;
public class PurchaseDemo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int cost=100;
int totalcost;
System.out.println("ENTER THE QUANTITY:");
int quantity = Integer.parseInt(sc.nextLine());
totalcost = quantity*cost;
if(totalcost>1000)
{
double totalcost1=totalcost-((10*totalcost)/100);
System.out.println("TOTAL COST : " + totalcost1);
}
else
{
System.out.println("TOTAL COST : " + totalcost);
}
sc.close();
}
}4.A company decided to give a bonus of 5% to the employee if his/her year of service is more than 5 years.Ask the user for their salary and year of service and print the net bonus amount.EmployeeDemo.javaimport java.util.Scanner;
public class EmployeeDemo {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int service_year;
double salary;
System.out.println("ENTER YOUR SERVICE YEAR");
service_year=Integer.parseInt(sc.nextLine());
System.out.println("ENTER YOUR SALARY");
salary=Double.parseDouble(sc.nextLine());
if(service_year>5)
{
double net_bonus=salary+((5*salary)/100);
System.out.println("NET BONUS : "+net_bonus);
}
else
{
System.out.println("NET BONUS : "+salary);
}
sc.close();
}
}5.Write a program to print the absolute value of a number entered by the user.E.g.- AbsoluteDemo.javaimport java.util.Scanner;
public class AbsoluteDemo {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("ENTER A NUMBER");
int n=Integer.parseInt(sc.nextLine());
if(n>0)
{
System.out.println("The number is: "+n);
}else{
System.out.println("The number is: "+Math.abs(n));
}
sc.close();
}
}6.Write a program to check whether an entered character is lowercase ( a to z ) or uppercase ( A to Z ). (Hint - You can use the ASCII value of the character)AsciiDemo.javaimport java.util.Scanner;
public class AsciiDemo {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("ENTER A CHARACTER");
char ch=sc.next().charAt(0);
int a=(int)ch;
if(a>=97 && a<=122)
System.out.println(String.format("%s is Lower case",ch));
if(a>=65 && a<=90)
System.out.println(String.format("%s is Upper case ",ch));
sc.close();
}
}7.A student will not be allowed to sit in an exam if his/her attendance is less than 75%.Take the following input from the user AttendanceDemo.javaimport java.util.Scanner;
public class AttendanceDemo {
public static void isAllowed(int total_class,int class_attend)
{
double percentage=(class_attend*100)/total_class;
System.out.println("TOTAL NO OF CLASSES :"+total_class);
System.out.println("NO OF CLASSES ATTENDED :"+class_attend);
System.out.println("ATTENDANCE PERCENTAGE :"+percentage);
if(percentage<75.00)
{
System.out.println("STATUS FOR WRITING EXAM : NOT ALLOWED");
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("ENTER THE TOTAL NO OF CLASSES");
int total_class=Integer.parseInt(sc.nextLine());
System.out.println("ENTER THE NO OF CLASSES ATTENDED");
int class_attend=Integer.parseInt(sc.nextLine());
isAllowed(total_class,class_attend);
sc.close();
}
}8.Modify the above question to allow the student to sit if he/she has a medical cause. Ask the user if he/she has a medical cause or not ( 'Y' or 'N' ) and print accordingly.AttendanceDemo1.javaimport java.util.Scanner;
public class AttendanceDemo1 {
public static void isAllowed(int total_class,int class_attend,char ch)
{
double percentage=(class_attend*100)/total_class;
System.out.println("TOTAL NO OF CLASSES :"+total_class);
System.out.println("NO OF CLASSES ATTENDED :"+class_attend);
System.out.println("ATTENDANCE PERCENTAGE :"+percentage);
if(percentage>75.00 || ch=='Y')
{
System.out.println("STATUS FOR WRITING EXAM : ALLOWED");
}
else{
System.out.println("STATUS FOR WRITING EXAM : NOT ALLOWED");
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("ENTER THE TOTAL NO OF CLASSES");
int total_class=Integer.parseInt(sc.nextLine());
System.out.println("ENTER THE NO OF CLASSES ATTENDED");
int class_attend=Integer.parseInt(sc.nextLine());
System.out.println("IS SHE HAS A MEDICAL CAUSE ?(Y/N)");
char ch=sc.next().charAt(0);
isAllowed(total_class,class_attend,ch);
sc.close();
}
}
|
Beta Was this translation helpful? Give feedback.
-
1public class MainClass {
public static void main(String[] args)
{
int length = 5;
int breadth = 5;
if (length==breadth)
System.out.print("Yes,It's Square");
else
System.out.print("No,It's not a Square");
}
}2.public class MainClass {
public static void main(String[] args)
{
int x = 7;
int y = 6;
if (x==y)
System.out.print("Both Values are same. ");
else
if(x>y){
System.out.print(x+" is greater value");
}
else
System.out.print(y+" is greater value");
}
}3.public class MainClass {
public static void main(String[] args)
{
int qty=90;
int amt=100*qty;
if (amt>1000){
int discount=amt*10/100;
amt=amt-discount;
System.out.println("Amount with discount :"+amt);
}
else{
System.out.println("Amount without discount "+amt);
}
}
}4.public class MainClass {
public static void main(String[] args)
{
int salary = 9000;
int service = 5;
if(service>=5){
double netamount = salary+salary*0.05;
System.out.println("salary with 5% bonus "+netamount);
}
else{
System.out.println("salary "+salary);
}
}
}5.public class MainClass {
public static void main(String[] args)
{
int number = -5;
if(number < 0){
number = number*(-1);
}
System.out.println("Result "+number);
}
}7,8. import java.util.*;
public class MainClass
{
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
System.out.print("no of classes held : ");
int held = Integer.parseInt(sc.nextLine());
System.out.print("no of classes attended : ");
int attended = Integer.parseInt(sc.nextLine());
System.out.print("medicalCase : ");
String medicalCause = sc.nextLine();
int percentage = (attended*100)/held;
System.out.println("percentage of the student : "+percentage);
if(percentage >75 && !medicalCause.equalsIgnoreCase("Y"))
{
System.out.println("Student allowed in the exam ");
}else{
System.out.println("Student not allowed in the exam ");
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Code4import java.util.*;
public class A {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
double salary = scan.nextInt();
int year = scan.nextInt();
System.out.println(salary);
int bonus=0;
if(year>=5){
salary=salary*0.05;
bonus=(int)salary;
}
System.out.println(bonus);
}
} |
Beta Was this translation helpful? Give feedback.
-
Code2import java.util.Scanner;
public class C {
public static void main(String[] args) {
Scanner S = new Scanner(System.in);
System.out.println("A: ");
int A = Integer.parseInt(S.next());
System.out.println("B:");
int B = Integer.parseInt(S.next());
if(A>B) {
System.out.println("A is Greater than B");
}else {
System.out.println("B is Greater than A");
}
}
} |
Beta Was this translation helpful? Give feedback.
-
2import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n1 = Integer.parseInt(sc.nextLine());
int n2 = Integer.parseInt(sc.nextLine());
if(n1 > n2){
System.out.println(n1 + ": is Greatest");
}else{
System.out.println(n2 + ": is Greatest");
}
sc.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
code1package com.example.futurense;
import java.util.Scanner;
public class Discussion891 {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
System.out.println("Enter the length and breadth of rectangle:");
int length=sc.nextInt();
int breadth=sc.nextInt();
if(length==breadth) `{`
System.out.println("it is a square....");
}
else
System.out.println("its a rectangle....");
}
}
code2package com.example.futurense;
import java.util.Scanner;
public class Discussion824 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("enter the salary:");
int salary=sc.nextInt();
System.out.println("Enter the year of experience");
int experience=sc.nextInt();
if(experience>5){
double bonus= salary*5/100;
System.out.println("your bonus ammount is: " +bonus);
}
else{
System.out.println("you are not eligible for bonus because you are not having 5 years of experience");
}
}
} |
Beta Was this translation helpful? Give feedback.
-
3import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the quantity:");
int quantity = Integer.parseInt(sc.nextLine());
int total = 0;
int discount = 0;
total = quantity * 100;
if(total > 1000){
discount = (10 * total) / 100;
}
int totalPay = total - discount;
System.out.println(totalPay);
sc.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
5import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
System.out.println(Math.abs(n));
sc.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
1import java.util.* ;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in) ;
System.out.println("Enter length: ");
int length = Integer.parseInt(sc.nextLine()) ;
System.out.println("Enter width: ");
int width = Integer.parseInt(sc.nextLine()) ;
if(length == width){
System.out.println("Its a Sqaure");
}else{
System.out.println("Its a Rectangle");
}
}
}2import java.util.* ;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in) ;
System.out.println("Enter Number 1: ");
int a = Integer.parseInt(sc.nextLine()) ;
System.out.println("Enter Number 2: ");
int b = Integer.parseInt(sc.nextLine()) ;
if(a > b ){
System.out.println(a);
}else{
System.out.println(b);
}
}
}
3import java.util.* ;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in) ;
System.out.println("Enter Quantity : ");
int a = Integer.parseInt(sc.nextLine()) ;
if(a*100 > 1000 ){
int net = (a * 100) * 9/10 ;
System.out.println("Amount after 10% discount " + net);
}else{
System.out.println("No discount");
}
}
}4import java.util.* ;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in) ;
System.out.println("Enter Salary : ");
int a = Integer.parseInt(sc.nextLine()) ;
System.out.println("Enter Tenure : ");
int b = Integer.parseInt(sc.nextLine()) ;
if(b > 5 ){
int bonus = a * 1/20 ;
System.out.println("Your Bonus Amount is " + bonus);
}else{
System.out.println("Not eligible for Bonus.");
}
}
}5import java.util.* ;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in) ;
System.out.println("Enter Number : ");
int a = Integer.parseInt(sc.nextLine()) ;
if(a < 0 ){
System.out.println("Absolute Value " + Math.abs(a));
}else if (a > 0){
System.out.println(a);
}else {
System.out.println("0");
}
}
}6import java.util.* ;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in) ;
System.out.println("Enter Character : ");
char c = sc.nextLine().charAt(0) ;
int a = c ;
if(a >= 65 && a <= 90 ){
System.out.println("Entered Char is UpperCase");
}else if (a >= 97 && a <= 122){
System.out.println("Entered Char is LowerCase");
}else {
System.out.println("Please enter Valid Character");
}
}
}7import java.util.* ;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in) ;
System.out.println("Enter Total Number of Classes : ");
int classes = Integer.parseInt(sc.nextLine()) ;
System.out.println("Enter Number of Classes attended: ");
int attended = Integer.parseInt(sc.nextLine()) ;
double minAttendance = classes * 3 / 4 ;
if(attended >= minAttendance){
System.out.println("Allow");
}else{
System.out.println("Not Allowed");
}
}
}8import java.util.* ;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in) ;
System.out.println("Enter Total Number of Classes : ");
int classes = Integer.parseInt(sc.nextLine()) ;
System.out.println("Enter Number of Classes attended: ");
int attended = Integer.parseInt(sc.nextLine()) ;
System.out.println("Any Medical Condition: ");
char msg = sc.nextLine().charAt(0) ;
double minAttendance = classes * 3 / 4 ;
if(attended >= minAttendance){
System.out.println("Allowed");
}else if(attended < minAttendance && msg == 'Y'){
System.out.println("Allowed");
}else{
System.out.println("Not Allowed");
}
}
} |
Beta Was this translation helpful? Give feedback.
-
6import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
char c = sc.nextLine().charAt(0);
int val = c; //typecasting
if(val >= 97 && val <= 122){
System.out.println("Entered value is in Lowercase");
}else{
System.out.println("Entered value is in uppercase");
}
sc.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
code2public class A{
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the first value");
int a = sc.nextInt();
System.out.println("Enter the second value);
int b = sc.nextInt();
if(a>b){
System.out.println("a value is greatest");
}
else{
System.out.println("b value is greatest");
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Code5import java.util.Scanner;
public class E {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("Enter the Number");
int num = Integer.parseInt(s.next());
if(num>0) {
System.out.println("The number is" + num);
}else {
System.out.println("The number is:"+Math.abs(num));
}
s.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
Code6import java.util.Scanner;
public class F {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("Enter a charachter:");
char a = s.next().charAt(0);
if(a>=65 && a<=90 ) {
System.out.println("the character is in UpperCase");
}
if(a>=97 && a>=122) {
System.out.println("The character is in lowerCase");
}
s.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
7import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int numOfClass = Integer.parseInt(sc.nextLine());
int classAttended = Integer.parseInt(sc.nextLine());
double Percentage = (classAttended * 100) / numOfClass;
if(Percentage < 75){
System.out.println("Student not allowed");
}
else{
System.out.println("Student are allowed");
}
sc.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
Code2import java.util.Scanner;
public class C {
public static void main(String[] args) {
Scanner S = new Scanner(System.in);
System.out.println("A: ");
int A = Integer.parseInt(S.next());
System.out.println("B:");
int B = Integer.parseInt(S.next());
if(A>B) {
System.out.println("A is Greater than B");
}else {
System.out.println("B is Greater than A");
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Code3import java.util.Scanner;
public class D {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("Enter the quantity");
double quant = Double.parseDouble(s.next());
double cost = quant*100;
double discount = 0;
double total_cost = 0;
if(cost>1000) {
discount = cost*0.1;
total_cost = cost - discount;
}
System.out.println("total cost = "+total_cost);
}
} |
Beta Was this translation helpful? Give feedback.
-
8import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int numOfClass = Integer.parseInt(sc.nextLine());
int classAttended = Integer.parseInt(sc.nextLine());
double Percentage = (classAttended * 100) / numOfClass;
if(Percentage < 75){
System.out.println("do you have medical cause? Y/N");
char c = sc.nextLine().charAt(0);
if(c == 'Y'){
System.out.println("Student are allowed");
}
else{
System.out.println("Student are not allowed");
}
}
else{
System.out.println("Student are allowed");
}
sc.close();
}
} |
Beta Was this translation helpful? Give feedback.








Uh oh!
There was an error while loading. Please reload this page.
-
Take values of the length and breadth of a rectangle from the user and check if it is square or not.
Take two int values from the user and print the greatest among them.
A shop will give a discount of 10% if the cost of the purchased quantity is more than 1000.
Ask the user for the quantity.
Suppose, one unit will cost 100.
Judge and print the total cost for the user.
A company decided to give a bonus of 5% to the employee if his/her year of service is more than 5 years.
Ask the user for their salary and year of service and print the net bonus amount.
Write a program to print the absolute value of a number entered by the user.
E.g.-
INPUT: 1 OUTPUT: 1
INPUT: -1 OUTPUT: 1
Write a program to check whether an entered character is lowercase ( a to z ) or uppercase ( A to Z ). (Hint - You can use the ASCII value of the character)
A student will not be allowed to sit in an exam if his/her attendance is less than 75%.
Take the following input from the user
And print,
Modify the above question to allow the student to sit if he/she has a medical cause. Ask the user if he/she has a medical cause or not ( 'Y' or 'N' ) and print accordingly.
Beta Was this translation helpful? Give feedback.
All reactions