Task - Operators - Practice Problems #80
Replies: 15 comments
1.ArithmeticOperpackage Operators;
public class ArithmeticOperator {
public static void main(String[] args) {
int a=2345;
System.out.println((((a+8)/3)%5)*5);
}
}2.AssignmentOperpackage Operators;
public class AssignmentOper{
public static void main(String[] args) {
int a=2345;
a+=8;
a/=3;
a%=5;
a*=5;
System.out.println(a);
}
}3,4.Logical AND, ORpackage Operators;
public class Relational {
public static void main(String[] args) {
int a=55;
int b=70;
System.out.println((a<50)&&(a<b));
System.out.println((a<50)||(a<b));
}
}5.MarksAndPercentagepackage Operators;
public class MarksAndPercentage{
public static void main(String[] args) {
int sub1=78;
int sub2=45;
int sub3=62;
System.out.println("Total Marks of Robert is: " +(sub1+sub2+sub3));
System.out.println("Percents of Robert is: " +(double)((sub1+sub2+sub3)*100)/300);
}
}6.Swappingpackage Operators;
public class SwapTwoNum {
public static void main(String[] args) {
int a=6;
int b=8;
int temp;
temp=a;
a=b;
b=temp;
System.out.printf("After Swapping with temp variable: a=%d,b=%d\n",a,b);
a=a+b;
b=a-b;
a=a-b;
System.out.printf("After Swapping without temp variable: a=%d,b=%d",a,b);
}
}7.Fahrenheit to Celsiuspackage Operators;
public class FahrenheitToCelsius{
public static void main(String[] args) {
float a=102f;
System.out.printf("The celcius of "+a+" degree fahrenheit is : "+(a-32)/1.8);
}
}8.GradeCountpackage Operators;
public class Marks {
public static void main(String[] args) {
int TotalCount=90;
int c= (50*TotalCount)/100-20;
System.out.println("Total no. of girls secured 'A' grade = "+c);
}
}9.Sum of first and last second digitpackage Operators;
import java.util.Scanner;
public class DigitExtraction {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter 5 digit num :");
int a=Integer.parseInt(sc.nextLine());
int rem1=a/10000;
int rem2=(a%100)/10;
System.out.println("The Sum of First and Last Second Digit is " + (rem1+rem2));
sc.close();
}
}10.Add 2 to each digitpackage Operators;
import java.util.Scanner;
public class Add2ToEachDigit{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
int a=Integer.parseInt(sc.nextLine());
int rem1=((a/1000)+2)%10;
int rem2=(((a/100)%10)+2)%10;
int rem3=(((a/10)%10)+2)%10;
int rem4=((a%10)+2)%10;
int b=(((rem1*10+rem2)*10+rem3)*10)+rem4;
System.out.println(b);
sc.close();
}
} |
1.ArithmeticOperatorpublic class Ques1 {
public static void main(String[] args) {
System.out.println("The Result::"+(((2345+8)/3)%5)*5);
}
}2.AssignmentOperatorpublic class Ques2 {
public static void main(String[] args) {
int a=2345;
a+=8;
a/=3;
a%=5;
a*=5;
System.out.println("The result::"+a);
}
}3.LogicalOperator ANDpublic class Ques3 {
public static void main(String[] args) {
int a=55,b=70;
System.out.println((a<50)&&(a<b));
}
}4.LogicalOperator ORpublic class Ques4 {
public static void main(String[] args) {
int a=55,b=70;
System.out.println((a<50)||(a<b));
}
}5.Total marks and Percentagepublic class Ques5 {
public static void main(String[] args) {
int mark1=78,mark2=45,mark3=62,sum=0;
sum=(mark1+mark2+mark3);
System.out.println("Total marks="+sum);
System.out.println("Average marks="+(sum/3));
}
}6.1.Swap Using Third variablepublic class Ques6_1 {
public static void main(String[] args) {
int a=6,b=8,temp;
System.out.println("Before Swapping::"+a+" "+b);
temp=a;
a=b;
b=temp;
System.out.println("After Swapping::"+a+" "+b);
}
}6.2.Swap without using third variablepublic class Ques6_2 {
public static void main(String[] args) {
int a=6,b=8;
System.out.println("Before Swapping::"+a+" "+b);
a=a+b;
b=a-b;
a=a-b;
System.out.println("After Swapping::"+a+" "+b);
}
}7.Fahrenheit into Celsiusimport java.util.Scanner;
public class Ques7 {
public static void main(String[] args) {
double f,c;
Scanner sc= new Scanner(System.in);
System.out.println("Enter degree in fahrenheit::");
f=sc.nextDouble();
c=(f-32)/1.8;
System.out.println("Degree in celsius::"+c);
sc.close();
}
}8.Girls count in 'A' Gradepublic class Ques8 {
public static void main(String[] args) {
int total=90;
int girls=(((50*total)/100)-20);
System.out.println("Total number of girls secured A Grade: "+girls);
}
} 9.Sum of First and last second Digitimport java.util.Scanner;
public class Ques9 {
public static void main(String[] args) {
int in,out,rem1=0,rem2=0;
Scanner sc =new Scanner(System.in);
System.out.print("Enter 5 digit number::");
in=sc.nextInt();
rem1=in/10000;
rem2=(in%100)/10;
out=rem1+rem2;
System.out.println("The output is: " + out);
sc.close();
}
}10. Add 2 to Each digitimport java.util.Scanner;
public class Ques10 {
public static void main(String[] args) {
int inp,out=0;
Scanner sc=new Scanner(System.in);
System.out.print("Enter 4 digit number: ");
inp=sc.nextInt();
out=(out*10)+((((inp/1000))+2)%10);
out=(out*10)+((((inp%1000)/100)+2)%10);
out=(out*10)+((((inp%100)/10)+2)%10);
out=(out*10)+(((inp%10)+2)%10);
System.out.println("The Result::"+out);
sc.close();
}
} |
1. Write a program to add 8 to the number 2345 and then divide it by 3. Now, the modulus of the quotient is taken with 5 and then multiply the resultant value by 5. Display the final result.public class OpDemo1 {
public static void main(String[] args) {
int num = (((2345+8)/3)%5)*5;
System.out.println("Result: "+num);
}
}2. Now, solve the above question using assignment operators (eg. +=, -=, *=).public class OpDemo1 {
public static void main(String[] args) {
int num=2345;
num+=8;
num/=3;
num%=5;
num*=5;
System.out.println("Result: "+num);
}
}3. Assign values of variables 'a' and 'b' as 55 and 70 respectively and then check if both the conditions 'a < 50' and 'a < b' are true.public class OpDemo1 {
public static void main(String[] args) {
int a = 55, b = 70;
System.out.println("Check both conditions "+(a<50)&&(a<b));
}
}4. Now solve the above question to check if at least one of the conditions 'a < 50' or 'a < b' is true.public class OpDemo1 {
public static void main(String[] args) {
int a = 55, b = 70;
System.out.println("Check if at least one of the conditions is true"+(a<50)||(a<b));
}
}5. If the marks of Robert in three subjects are 78,45 and 62 respectively (each out of 100 ), write a program to calculate his total marks and percentage marks.public class OpDemo1 {
public static void main(String[] args) {
int m1=78,m2=45,m3=62;
int t = m1+m2+m3;
double p = (double)t/300;
System.out.println("Total markS: "+t);
System.out.println("Percentage marks: "+ p*100 );
}
}6. Suppose the values of variables 'a' and 'b' are 6 and 8 respectively, write two programs to swap the values of the two variables.1 - first program by using a third variable public class Swapping {
public static void main(String[] args) {
int a = 6, b = 8;
System.out.println("using third variable");
System.out.println("before swapping");
System.out.println("a = "+a+" b = "+b);
int t=a;
a=b;
b=t;
System.out.println("after swapping");
System.out.println("a = "+a+" b = "+b);
System.out.println("\nwithout using third variable");
System.out.println("before swapping");
a=6; b=8;
System.out.println("a = "+a+" b = "+b);
a=a+b;
b=a-b;
a=a-b;
System.out.println("after swapping");
System.out.println("a = "+a+" b = "+b);
}
}7. Write a program to convert Fahrenheit into Celsius.import java.util.Scanner;
public class DegConv {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter fahrenheit value");
double f = sc.nextDouble();
double c = ((f-32)*5)/9;
System.out.println(String.format("%.2f degree fahrenheit is equal to %.2f degree celsius",f,c));
sc.close();
}
}8. The total number of students in a class are 90 out of which 45 are boys. If 50% of the total students secured grade 'A' out of which 20 are boys, then write a program to calculate the total number of girls getting grade 'A'.public class Students {
public static void main(String[] args) {
double tot=90;
int b=45;
double gradA = tot*(double)50/100;
System.out.println("Total number of students "+(int)tot);
System.out.println("Total number of boys "+b);
System.out.println("Total number of students getting grade 'A' = "+(int)gradA);
System.out.println("Total number of boys getting grade 'A' = 20");
gradA-=20;
System.out.println("Total number of girls getting grade 'A' = "+(int)gradA);
}
}9. Write a program to calculate the sum of the first and the second last digit of a 5 digit.INPUT: 12345 import java.util.Scanner;
public class EndDigSum {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a 5 digit number");
int n=Integer.parseInt(sc.nextLine());
int n1= n/10000;
int n2 = (n/10)%10;
System.out.println(String.format("Sum of the first and the second last digit %d and %d is %d",n1,n2,(n1+n2)));
}
}10. Take a 4 digit number. Write a program to display a number whose digits are 2 greater than the corresponding digits of the number TAKEN.For example, if the number which was taken is 5696, then the displayed number should be 7818. import java.util.Scanner;
public class EachDigSum {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a four digit number");
int n = Integer.parseInt(sc.nextLine());
int d1=n/1000 +2;
int d2=(n/100)%10 +2;
int d3=(n/10)%10 +2;
int d4=n%10 +2;
System.out.println(String.format("Result: %d%d%d%d",d1,d2,d3,d4));
}
} |
TASK - OPERATORS PRACTICE PROBLEM1. Write a program to add 8 to the number 2345 and then divide it by 3. Now, the modulus of the quotient is taken with 5 and then multiply the resultant value by 5. Display the final result.OperationDemo.javapublic class OperationDemo
{
public static void main(String[] args) {
int result=(((2345+8)/3)%5)*5;
System.out.println("Final_Result:"+ result);
}
}Output2.Now, solve the above question using assignment operators (eg. +=, -=, *=).CompoundOperationDemo.javapublic class CompoundOperationDemo {
public static void main(String[] args) {
int result=(((2345+8)/3)%5)*5;
System.out.println("Final_Result:"+ result);
System.out.println("VALUES FOR += ::"+ (result+=3));
System.out.println("VALUES FOR -= ::"+ (result-=3));
System.out.println("VALUES FOR *= ::"+ (result*=3));
}
}Output3.Assign values of variables 'a' and 'b' as 55 and 70 respectively and then check if both the conditions 'a < 50' and 'a < b' are true.4.Now solve the above question to check if at least one of the conditions 'a < 50' or 'a < b' is true.RelationalDemo .javapublic class RelationalDemo {
public static void main(String[] args) {
int a=55;
int b=70;
System.out.println("Result of && opeartion: " + ((a<50) && (a<b)));
System.out.println("Result of || opeartion: " + ((a<50) || (a<b)));
}
}Output5.If the marks of Robert in three subjects are 78,45 and 62 respectively (each out of 100 ), write a program to calculate his total marks and percentage marks.MarksDemo.javapublic class MarksDemo {
public static void main(String[] args) {
int mark1=78,mark2=45,mark3=62;
double total=mark1+mark2+mark3;
System.out.println("TOTAL MARKS:"+ total);
double percentage=(total/300)*100;
System.out.println("TOTAL PERCENTAGE MARKS: "+percentage);
}
}Output6.Suppose the values of variables 'a' and 'b' are 6 and 8 respectively, write two programs to swap the values of the two variables.1 - first program by using a third variableSwapDemo.javapublic class SwapDemo {
public static void main(String[] args) {
int a=6,b=8;
int temp;
System.out.println("SWAPPING OF TWO NUMBERS USING THIRD VARIABLE");
System.out.println(String.format("VALUES BEFORE SWAPPING : a = %d and b=%d",a,b));
temp=a;
a=b;
b=temp;
System.out.println(String.format("VALUES AFTER SWAPPING : a = %d and b=%d",a,b));
}
}Output2 - second program without using any third variable( Swapping means interchanging the values of the two variables E.g.- If entered value of x is 5 and y is 10 then after swapping the value of x and y should become 10 and 5 respectively.) SwapDemo1.javapublic class SwapDemo1 {
public static void main(String[] args) {
int a=6,b=8;
System.out.println("SWAPPING OF TWO NUMBERS WITHOUT USING THIRD VARIABLE");
System.out.println(String.format("VALUES BEFORE SWAPPING : a = %d and b=%d",a,b));
a=a+b;
b=a-b;
a=a-b;
System.out.println(String.format("VALUES AFTER SWAPPING : a = %d and b=%d",a,b));
}
}Output7.Write a program to convert Fahrenheit into Celsius.ConversionDemo.javaimport java.util.Scanner;
public class ConversionDemo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("ENTER A TEMPERATURE IN FARENHEIT :");
double farenheit=Double.parseDouble(sc.nextLine());
double celsius=(9.0/5.0)*farenheit - 32;
System.out.println("TEMPERATURE IN CELSIUS: "+celsius);
System.out.println("TEMPERATURE IN FARENHEIT: "+farenheit);
}
}Output8.The total number of students in a class are 90 out of which 45 are boys. If 50% of the total students secured grade 'A' out of which 20 are boys, then write a program to calculate the total number of girls getting grade 'A'.GradeDemo.javapublic class GradeDemo {
public static void main(String[] args) {
int n=90; //Total no of students
int b=45; //Total no of boys
System.out.println("PERCENTAGE OF STUDENTS SECURED GRADE A: " + 50+"%");
int student=(50*n)/100; //number of student secured grade A
System.out.println("NUMBER OF STUDENTS SECURED GRADE A: " + student);
System.out.println("NUMBER OF BOYS SECURED GRADE A: " + 20);
int g=student-20; //no of girls secured grade A
System.out.println("NUMBER OF GIRLS SECURED GRADE A: " + g);
}
}Output9.Write a program to calculate the sum of the first and the second last digit of a 5 digit.INPUT: 12345 DigitsDemo.javaimport java.util.Scanner;
public class DigitsDemo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("ENTER A FIVE DIGIT NUMBER :");
int n=Integer.parseInt(sc.nextLine());
int n1=n/10000;
int n2=(n/10)%10;
System.out.println(String.format("SUM OF FIRST AND SECOND LAST DIGIT OF %d is %d",n, (n1+n2)));
sc.close();
}
}Output10.Take a 4 digit number. Write a program to display a number whose digits are 2 greater than the corresponding digits of the number TAKEN.For example, if the number which was taken is 5696, then the displayed number should be 7818 DigitNumDemo.javaimport java.util.Scanner;
public class DigitNumDemo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("ENTER A FOUR DIGIT NUMBER :");
int n=Integer.parseInt(sc.nextLine());
int n1=n/1000+2;
int n2=(n/100)%10+2;
int n3=(n/10)%10+2;
int n4=n%10+2;
System.out.println(String.format("RESULTANT NUMBER is %d%d%d%d", n1,n2,n3,n4));
sc.close();
}
}Output |
1add8.javapublic class add8 {
public static void main(String[] args)
{
System.out.println((((2345+8)/3)%5)*5);
}
}Output2addop.javapublic class addop {
public static void main(String[] args)
{
int n=2345;
n+=8;
n/=3;
n%=5;
n*=5;
System.out.println(n);
}
}Output3.Perform.javapublic class Perfom {
public static void main(String args[])
{
int a=55;
int b=70;
System.out.println(a<50 && a<b);
}
}Output4.Perform.javapublic class Perfom {
public static void main(String args[])
{
int a=55;
int b=70;
System.out.println(a<50 || a<b);
}
}Output5.Robert.javapublic class Robert {
public static void main(String args[])
{
int sum=78+45+62;
float per=((sum)*100)/300;
System.out.println(String.format("The Total marks is %d\nPercentage: %.2f",sum,per));
}
}Output6.Swap.java1.public class swap {
public static void main(String[] args)
{
int a=6,b=8,temp=0;
System.out.println(String.format("Before Swapping a= %d b= %d",a,b));
temp=a;
a=b;
b=temp;
System.out.println(String.format("After Swapping a= %d b= %d",a,b));
}
}Output2.public class swap {
public static void main(String[] args)
{
int a=7,b=8;
System.out.println(String.format("Before Swapping a= %d b= %d",a,b));
a=a*b;
b=a/b;
a=a/b;
System.out.println(String.format("After Swapping a= %d b= %d",a,b));
}
}Output7.temp.javaimport java.util.Scanner;
public class temp {
public static void main(String args[])
{
Double temp;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the temperature in fahrenheit");
temp=Double.parseDouble(sc.nextLine());
temp=((temp-32)/1.8000);
System.out.println(String.format("The temperature in Celsius is %f",temp));
}
}Output8grade.javapublic class grade {
public static void main(String[] args)
{
System.out.println(String.format("The total students of A grade is %d \nThe boys of A grade are %d \nThe girls of B grade are %d \n",((50*90)/100),20,(((50*90)/100)-20)));
}
}Output9add14.javaimport java.util.*;
public class add14 {
public static void main(String[] args)
{
int n;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
n=Integer.parseInt(sc.nextLine());
n=n/10;
int four=n%10;
n=n/10;
n=n/10;
n=n/10;
System.out.println(String.format("The addition value of 1st and 4th are %d",(four+n)));
}
}Output10add2.javaimport java.util.Scanner; public class add2 {
public static void main(String[] args) {
int inp,out=0;
Scanner sc=new Scanner(System.in);
System.out.print("Enter 4 digit number: ");
inp=sc.nextInt();
out=(out*10)+((((inp/1000)%100)+2)%10);
out=(out*10)+((((inp%1000)/100)+2)%10);
out=(out*10)+((((inp%100)/10)+2)%10);
out=(out*10)+(((inp%10)+2)%10);
System.out.println(String.format("%d",out));
sc.close();
}
}Output |
1Arithmetic Operatorimport java.util.*;
public class AddMod{
public static void main(String[] args){
int num = 2345;
int result = ((((num+8)/3)%5)*5);
System.out.println("Final result: " + result);
}
}Output:2Assignment Operatorimport java.util.*;
public class AssignAdd{
public static void main(String[] args){
int num = 2345;
num+=8;
num/=3;
num%=5;
num*=5;
System.out.println("Final Result : "+num);
}
}Output:3Logical Operator ANDimport java.util.*;
public class AssignOp{
public static void main(String[] args){
int a=55, b=70;
System.out.println("Result : "+((a<50) && (a<b)));
}
}Output:4Logical Operator ORimport java.util.*;
public class AssignOr{
public static void main(String[] args){
int a=55, b=70;
System.out.println("Result : "+((a<50) || (a<b)));
}
}Output:5Total Marks and Percentageimport java.util.*;
public class Marks{
public static void main(String[] args){
int m1=78, m2=45,m3=62;
double total = m1+m2+m3;
System.out.println("Total marks of Robert = "+total);
double percentage = (total/300)*100;
System.out.println("Percentage marks = "+percentage);
}
}Output:6(1)Swapping using third variableimport java.util.*;
public class SwapNum{
public static void main(String[] args){
int a = 6, b = 8;
System.out.println("Before Swapping : "+"a : "+a+", b : "+b);
int temp;
temp = a;
a = b;
b = a;
System.out.println("After Swapping : "+"a : "+a+", b : "+b);
}
}Output:6(2)Swapping without using third variableimport java.util.*;
public class SwapNumbers{
public static void main(String[] args){
int a = 6, b = 8;
System.out.println("Before Swapping : "+" a : "+a+", b : "+b);
a = a+b;
b = a-b;
a = a-b;
System.out.println("After Swapping : "+" a : "+a+", b : "+b);
}
}Output:7Fahrenheit to Celsiusimport java.util.*;
public class FahCel{
public static void main(String[] args){
float Fahrenheit;
Scanner sc = new Scanner(System.in);
System.out.println("Enter Fahrenheit : ");
Fahrenheit = sc.nextFloat();
float Celsius = ((Fahrenheit-32)*5)/9;
System.out.println("Temperature in celsius is : "+Celsius);
}
}Output:8Count of girls secured 'A' gradeimport java.util.*;
public class GradeStud{
public static void main(String[] args){
int total=90, boys=45;
int A_Grade=50;
int A_Boys=20;
int Tot_Agradegirls = ((A_Grade*total)/100)-A_Boys;
System.out.println("Total number of girls secured A Grades are : "+Tot_Agradegirls);
}
}Output:9Sum of first and last second digitimport java.util.*;
public class FirstSecDig{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the 5 digit input : ");
int a = sc.nextInt();
int firstDig = (a/10000);
int secondLastDig = (a/10)%10;
int sum = firstDig + secondLastDig;
System.out.println("Sum of 1st and second last digits are : "+sum);
}
}Output:10Add 2 to each digitimport java.util.*;
public class SecondDig{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the 4 digit number : ");
int num = sc.nextInt();
int num1 = ((num/1000)%10+2)%10;
int num2 = ((num/100)%10+2)%10;
int num3 = ((num/10)%10+2)%10;
int num4 = ((num%10)+2)%10;
System.out.println("Result : "+num1+num2+num3+num4);
}
}Output: |
Problem Statements1. Arithmetic operatorpublic class Resultdemo {
public static void main(String[] args) {
int num=2345;
System.out.println("Final Result:"+((((num+8)/3)%5)*5));
}
}Output:2. Assignment Operatorpublic class FinalDemo {
public static void main(String[] args){
int num=2345;
num+=8;
num/=3;
num%=5;
num*=5;
System.out.println("Final Result:"+num);
}
}Output:3.Logical Operatorpublic class CheckProblm{
public static void main(String[] args){
int a=55;
int b=70;
System.out.println(a<50 && a<b);
}
}output:4 .Logical Operator(OR)public class CheckDemo {
public static void main(String[] args){
int a=55;
int b=70;
System.out.println(a<50 || a<b);
}
}output:5.Total percantagepublic class TotalProblm {
public static void main(String[] args){
int mark1=78; int mark2=45;
int mark3=62;
double total=mark1+mark2+mark3;
double percentage=(total/300)*100;
System.out.println("Total marks :"+total);
System.out.println("Percentage marks:"+percentage);
}
}output:6.i)Swapping using third variablepublic class SwapProgram {
public static void main(String[] args){
int a=6;int b=8;
int temp;
temp=a;
a=b;
b=temp;
System.out.printf("After swapping using third variable : a=%d, b=%d",a,b);
}
}Output:6.ii) Swapping using without any third variablepublic static void main(String[] args) {
int a=6;int b=8;
a=a+b;
b=a-b;
a=a-b;
System.out.printf("After swapping a=%d, b=%d",a,b);
}
}output:7.Fahrenheit to celsiuspublic class FahrenheitProgrm {
public static void main(String[] args){
double Fahrenheit= 50,celsius;
celsius=((Fahrenheit-32)*5)/9;
System.out.println("Celsius is "+celsius);
}
}output:8.Grade problempublic class GradeProblm {
public static void main(String[] args){
int total_no_students=90;
int total_boys=45;
int Gradepercent=50;
int Gradeboys=20;
int Gradegirls=((Gradepercent*total_no_students)/100)-Gradeboys;
System.out.println("Total no of girls getting grade 'A' is "+ Gradegirls);
}
}output:9.Sum of the first and second last digitpublic class DigitDemo {
public static void main(String[] args){
int digit=12345,no_of_digits=5;
int power=(int) Math.pow(10,(no_of_digits-1));
int First_digit=digit/power;
System.out.println("First digit: " +First_digit);
int secondLastDigit=(digit/10)%10;
System.out.println("Second digit:"+secondLastDigit);
int result=First_digit+secondLastDigit;
System.out.println("Output: " +result);
}}output:10.Display Numberimport java.util.Scanner;
public class DisplayNumber{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Taken number:");
int taken=sc.nextInt(); int no_of_digits=4;
int power=(int) Math.pow(10,(no_of_digits-1));
int n1=((taken/power)+2)%10;
int n2=(((taken/100)%10)+2)%10;
int n3=((taken/10)+2)%10;
int n4=((taken%10)+2)%10;
System.out.printf("Displayed number is %d%d%d%d",n1,n2,n3,n4);
}
}output: |
1class Arithmetic1{
public static void main(String[] args) {
System.out.println("The Final result is "+(((2345 +8)/3)%5)*5);
}
}2public class Operators2 {
public static void main(String[] args) {
int number=2345;
number+=8;number/=3;number%=5;number*=5;
System.out.println("The result is " + number);
}
}3public class Operator3 {
public static void main(String[] args) {
int a =55,b =70;
System.out.println((a<50 && a<b));
}
}4public class Operator4 {
public static void main(String[] args) {
int a=55 , b=70;
System.out.println((a<50 || a<b));
}
}5public class Operator5 {
public static void main(String[] args) {
int s1=78,s2=45,s3=62;
int total;
float percentage;
total = s1+s2+s3;
percentage=(float)total/3;
System.out.println("Robert total marks "+total);
System.out.println("Percentage marks "+percentage);
}
}6public class Operator6 {
public static void main(String[] args) {
int a =6,b=8;
System.out.println("Before Swapping\t"+a);
System.out.println("Before Swapping\t"+b);
int c=a;a=b;b=c;
System.out.println("After Swapping\t"+a);
System.out.println("After Swapping\t"+b);
a+=b;b=a-b;a-=b;
System.out.println("After Swapping Without third variable\t"+a);
System.out.println("After Swapping Without third variable\t"+b);
}
}7public class Operator7 {
public static void main(String[] args) {
float f = 123.456f;
float c = ((f-32)*5)/9;
System.out.println("celsius: " + c);
}
}8class Operator8{
public static void main(String[] args) {
int noOfStudents = 90;
int girls = ((noOfStudents*50)/100)-20;
System.out.println("Total number of girls getting grade 'A'\t"+girls);
}
}9public class Operator9 {
public static void main(String[] args) {
int input= 12345;
int ld= (input%100)/10;
int fd=input/10000;
System.out.println(ld);
System.out.println(fd);
System.out.println("Output:" +(fd+ld));
}
}10public class Operator10 {
public static void main(String[] args) {
int digit =5696;
int ld=digit%10;ld+=2;
digit/=10;
int sld=digit%10;sld+=2;sld%=10;
digit/=10;
int tld=digit%10;tld+=2;
int fd=digit/10;fd+=2;
int number=fd;
number=(number*10)+tld;
number=(number*10)+sld;
number=(number*10)+ld;
System.out.println(number);
}
} |
Problem 1public class OperatorsProblem1 {
public static void main(String[] args) {
int result=((((2345+8)/3)%5)*5);
System.out.println("The Result is : "+result);
}
}Problem 2public class OperatorsProblem2 {
public static void main(String[] args) {
int number=2345;
number+=8;
number/=3;
number%=5;
number*=5;
System.out.println("The Result is: "+number);
}
}Problem 3public class OperatorsProblem3 {
public static void main(String[] args) {
int a=55;
int b=70;
System.out.println("The Condition is : "+(a<50 && a<b));
}
}Problem 4public class OpertorsProblem4 {
public static void main(String[] args) {
int a=55;
int b=70;
System.out.println("Atlest one of the condition is : "+(a<50 || a<b));
}
}Problem 5public class OperatorsProblem5 {
public static void main(String[] args) {
float subject1=78;
float subject2=45;
float subject3=62;
float total=subject1+subject2+subject3;
System.out.println("The total marks of Robert is(out of 300) : " + total);
float percentage=total/3;
System.out.println("The Percentage marks of Robert is: " + percentage);
}
}Problem 6public class OperatorsProblem6 {
public static void main(String[] args) {
int a=6,b=8,c;
//by using a third variable
System.out.printf("%nBefore Swapping Values:\t a is %d, b is %d",a,b);
c=a;
a=b;
b=c;
System.out.printf("%nAfter Swapping Values :\t a is %d, b is %d",a,b);
System.out.println();
// without using any third variable
System.out.printf("%nBefore Swapping Values:\t a is %d, b is %d",a,b);
a+=b;
b=a-b;
a-=b;
System.out.printf("%nAfter Swapping Values :\t a is %d, b is %d",a,b);
}
}Problem 7import java.util.Scanner;
public class OperatorsProblem7 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the temperature in Fahrenheit: ");
float Fahrenheit = sc.nextFloat();
double Celsius=(9.0/5.0)* Fahrenheit-32;
System.out.println("The temperature in Celsius : " + Celsius);
sc.close();
}
}Problem 8public class OperatorsProblem8 {
public static void main(String[] args) {
int noOfStudents=90;
int girls=((noOfStudents*50)/100)-20;
System.out.println("the total number of girls getting grade 'A' : "+girls);
}
}Problem 9public class OperatorsProblem9 {
public static void main(String[] args) {
//int number=12345;
Scanner sc=new Scanner(System.in);
System.out.println("Enter any five digit number: ");
int number=sc.nextInt();
int seconLlastNum=number%100;
seconLlastNum/=10;
int firstNum=number/10000;
System.out.print("The sum of the first and the second last digit of a 5 digit: "+(seconLlastNum+firstNum));
sc.close();
}
}Problem 10import java.util.Scanner;
public class OperatorsProblem10 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter any 4 digit number: ");
int number=sc.nextInt();
int ld=number%10;
ld+=2;
number/=10;
int sld=number%10;
sld+=2;
sld%=10;
number/=10;
int tld=number%10;
tld+=2;
int fd=number/10;
fd+=2;
int join=fd;
join=(join*10)+tld;
join=(join*10)+sld;
join=(join*10)+ld;
System.out.println(join);
sc.close();
}
} |
1package operator;
public class Numbers {
public static void main(String[] args) {
int inputNumber = 2345;
double finalResult = ((((8 + inputNumber) / 3) % 5) * 5);
System.out.println("final result is: " + finalResult);
}
}2package operator;
import java.util.*;
public class AssignmentOperatorDemo {
public static void main(String[] args) {
Scanner obj = new Scanner(System.in);
System.out.println("Enter the number 1:");
int fstNumber = obj.nextInt();
System.out.println("Enter the number 2:");
int scndNumber = obj.nextInt();
System.out.println(fstNumber += scndNumber);
System.out.println(fstNumber -= scndNumber);
System.out.println(fstNumber /= scndNumber);
System.out.println(fstNumber %= scndNumber);
obj.close();
}
}3package operator;
public class RelationalOperatorDemo {
public static void main(String[] args) {
int fstNumber = 55;
int scndNumber = 70;
System.out.println((fstNumber < 50) && (fstNumber < scndNumber));
}
}4package operator;
public class RelationalOperatorWithCondition {
public static void main(String[] args) {
int fstNumber = 55;
int scndNumber = 70;
System.out.println((fstNumber < 50) || (fstNumber < scndNumber));
}
}5package operator;
public class MarkCalculation {
public static void main(String[] args) {
int subjectOne = 78;
int subjectTwo = 45;
int subjectThree = 62;
int totalMarks = subjectOne + subjectTwo + subjectThree;
double percentageOfMarks = ((totalMarks * 100) / 300);
System.out.println("total marks for the three subject:" + totalMarks);
System.out.println("percentage of the total mark:" + percentageOfMarks);
}
}6package operator;
import java.util.*;
public class SwappingDemo {
public static void main(String[] args) {
Scanner obj = new Scanner(System.in);
System.out.println("Enter the first number:");
int firstNumber = obj.nextInt();
System.out.println("Enter the second number:");
i) int secondNumber = obj.nextInt();
int temp = firstNumber;
firstNumber = secondNumber;
secondNumber = temp;
System.out.println("swappig with temp variable:firstNumber= " + firstNumber + " secondNumber= " + secondNumber);
ii) firstNumber = firstNumber + secondNumber;
secondNumber = firstNumber - secondNumber;
firstNumber = firstNumber - secondNumber;
System.out.println(
"swappig without temp variable:firstNumber= " + firstNumber + " secondNumber= " + secondNumber);
obj.close();
}
}7package operator;
import java.util.*;
public class FahrenheitToCelsius {
public static void main(String[] args) {
Scanner obj = new Scanner(System.in);
System.out.println("Enter your fahrenheit value:");
int fahrenheit = obj.nextInt();
float celsius = ((fahrenheit - 32) * 5) / 9;
System.out.println("fahrenheit to celsius: " + celsius);
obj.close();
}
}8package operator;
public class StudentGrade {
public static void main(String[] args) {
int noOfStudent = 90;
int gradeAStudent = (noOfStudent * 50) / 100;
int gradeAGirlsStudent = gradeAStudent - 20;
System.out.println("Grade A girls are:" + gradeAGirlsStudent);
}
}9package operator;
public class DigitsIdentifyDemo {
public static void main(String[] args) {
int inputNumber = 12345;
int firstDigit = inputNumber / 10000;
int lastSecondDigit = ((inputNumber / 10) % 10);
System.out.println("firstDigit= " + firstDigit + " last second digit= " + lastSecondDigit);
}
}10package operator;
import java.util.*;
public class DisplaySecondGreaterNumberDemo {
public static void main(String[] args) {
Scanner obj = new Scanner(System.in);
System.out.println("Enter the input number:");
int inputNumber = obj.nextInt();
String secondGreaterNumber = "";
secondGreaterNumber += ((inputNumber / 1000) + 2) % 10;
secondGreaterNumber += (((inputNumber / 100) % 10) + 2) % 10;
secondGreaterNumber += (((inputNumber / 10) % 10) + 2) % 10;
secondGreaterNumber += ((inputNumber % 10) + 2) % 10;
System.out.println("the two greater number" + Integer.parseInt(secondGreaterNumber));
obj.close();
}
} |
1.Arithmetic Operatorpublic class ArithmeticOperator
{
public static void main(String[] args) {
int a=((((2345+8)/3)%5)*5);
System.out.println("Result Value is "+a);
}
}2.AssignmentOperatorpublic class AssignmentOperator {
public static void main(String[] args) {
int a=2345;
a+=8;
a/=3;
a%=5;
a*=5;
System.out.println("Result Value is "+a);
}
}3.4 Logicalpublic class LogicalOperator {
public static void main(String[] args) {
int a=55;
int b=70;
System.out.println((a<50) && (a<b));
System.out.println((a<50)||(a<b));
}
}5. Percentagepublic class Percentage {
public static void main(String[] args) {
int subject1=70;
int subject2=85;
int subject3=52;
System.out.println("Total "+(subject1+subject2+subject3));
System.out.println("Percentage "+(double)((subject1+subject2+subject3)*100)/300);
}
}6.Swapping Numberspublic class Swapping {
public static void main(String[] args) {
int a=7;
int b=8;
a=a+b;
b=a-b;
a=a-b;
System.out.printf("Swapping without temp variable a=%d and b=%d\n",a,b);
int temp=a;
a=b;
b=temp;
System.out.printf("Swapping with temp variable a=%d and b=%d",a,b);
}
}7.Conversion from C to Fpublic class Temperature {
public static void main(String[] args) {
float fahrenheit=98f;
System.out.printf("Temperature in Celcius %.2f C",((fahrenheit-32)*5/9));
}
}8.Grade9.Sum of digitpublic class SumDigit {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter 5 digit num :");
int a=Integer.parseInt(sc.nextLine());
int remainder=a/10000;
System.out.printf("Sum of digit is %d students is ",(remainder+((a%100)/10)));
sc.close();
}
}
}10. Sum of two digitspublic class SumofNumber {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter num :");
int n=Integer.parseInt(sc.nextLine());
int remainder1=n/1000+2;
int remainder2=(n/100)%10+2;
int remainder3=(n/10)%10+2;
int remainder4=n%10+2;
System.out.println(String.format("The Number is %d", (remainder1*1000+remainder2*100+remainder3*10+remainder4)));
sc.close();
}
} |
1public class Arithmetic {
public static void main(String[] args){
int a=2345;
int b=a+8;
int c=b/3;
int d=c%5;
int e=d*5;
System.out.println(e);
}
}2public class Assignment {
public static void main(String[] args){
int a=2345;
a+=8;
a/=3;
a%=5;
a*=5;
System.out.println(a);
}
}3,4public class Logical {
public static void main(String[] args){
int a=55,b=70;
System.out.println((a<50)&&(a<b));
System.out.println((a<50)||(a<b));
}
}5public class Marks {
public static void main(String[] args){
int tamil=78;
int english=45;
int maths=62;
int total=tamil+english+maths;
double percent=(total*100)/300;
System.out.println("Robert Total Marks:"+total);
System.out.println("Robert Percenrtage is :"+percent);
}
}6public class Swapping {
public static void main(String[] args){
int a=6,b=8;
int thirdVar;
thirdVar=a;
a=b;
b=thirdVar;
System.out.println("a: " + a + " b: " + b);
a=a+b;
b=a-b;
a=a-b;
System.out.println("a: " + a + " b: " + b);
}
}7public class Celsius {
public static void main(String[] args){
float Fahrenheit=50;
float Celsius=(((Fahrenheit-32)*5)/9);
System.out.println("Celsius of Fahrenheit 50 is:"+Celsius);
}
}8public class Grade {
public static void main(String[] args){
int students=90;
int boys=50;
int girls=(((boys*students)/100)-20);
System.out.println("Total girls: " + girls);
}
}9import java.util.Scanner;
public class SumOfDigits {
public static void main(String[] args){
Scanner sc= new Scanner(System.in);
System.out.println("Enter any 5 digit number");
int num=sc.nextInt();
int firstDigit=num/10000;
System.out.println("first digit: " + firstDigit);
int secondDigit=(num/10);
System.out.println("The last second digit: " + secondDigit);
int sum=firstDigit+secondDigit;
System.out.println("The sum of first and last second digit is:"+sum);
}
}10import java.util.Scanner;
public class Add2toEach {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter any 4 digit number");
int n=sc.nextInt();
int num1=((n/1000)+2)*1000;
int num2=(((n/100)%10)+2)*100;
int num3=(((n/10)%10)+2)*10;
int num4=(n%10)+2;
System.out.println("The number is:"+(num1+num2+num3+num4));
}
} |
1 public class MainClass {
public static void main(String[] args) {
int a=2345;
int value = (((a+8)/3)%5)*5;
System.out.println(value);
}
}2public class MainClass{
public static void main(String[] args) {
int var1 =2345;
var1 += 8;
var1 /= 3;
var1 %= 5;
var1 *= 5;
System.out.println("var1 "+var1);
}
}3 public class MainClass {
public static void main(String[] args) {
int a=55,b=70;
boolean value = (a<50)&&(a<b);
System.out.println(value);
}
}4public class MainClass {
public static void main(String[] args) {
int a=55,b=70;
boolean value = (a<50)||(a<b);
System.out.println(value);
}
}5 public class MainClass {
public static void main(String[] args){
int tamil=78; int english=45;
int maths=62;
double totalvalue = tamil+english+maths;
double percentage=(totalvalue/300)*100;
System.out.println("Total marks :"+totalvalue);
System.out.println("Percentage marks:"+percentage);
}6.swapping using third variablepublic class MainClass {
public static void main(String[] args){
int a=6;int b=8;
int temp;
temp=a;
a=b;
b=temp;
System.out.printf("After swapping using third variable : a=%d, b=%d",a,b);
}
}6.swapping without third variablepublic class MainClass {
public static void main(String[] args) {
int a=6;int b=8;
a=a+b;
b=a-b;
a=a-b;
System.out.printf("After swapping a=%d, b=%d",a,b);
}
}7public class MainClass {
public static void main(String[] args){
float fahrenheit=50;
float celsius=(((fahrenheit-32)*5)/9);
System.out.println(Celsius);
}
}8public class MainClass {
public static void main(String[] args) {
int TotalCount=90;
int c= (50*TotalCount)/100-20;
System.out.println("Total no. of girls secured 'A' grade = "+c);
}
}9public class DigitsIdentifyDemo {
public static void main(String[] args) {
int a = 12345;
int b = a / 10000;
int c = ((a / 10) % 10);
System.out.println("firstDigit= " + b + " last second digit= " + c);
}
} |
1public class OperatorsExample {
public static void main(String[] args) {
int num=2345;
int res = (((num+8)/3)%5)*5;
System.out.println(res);
}
}2public class OperatorsExample{
public static void main(String[] args) {
int num =2345;
num += 8;
num /= 3;
num %= 5;
num *= 5;
System.out.println(num);
}
}3,4public class OperatorsExample{
public static void main(String[] args){
int n1=55;
int n2=70;
System.out.println(n1<50 && n1<n2);
System.out.println(n1<50 || n1<n2);
}
}5public class OperatorsExample {
public static void main(String[] args){
int m1=78; int m2=45;
int m3=62;
double total=m1+m2+m3;
double percentage=(total/300)*100;
System.out.println("Total marks :"+total);
System.out.println("Percentage marks:"+percentage);
}
}6public class OperatorsExample {
public static void main(String[] args) {
int n1=6,n2=8;
System.out.println("Before Swapping "+n1);
System.out.println("Before Swapping "+n2);
int temp=n1;
n1=n2;
n2=temp;
System.out.println("After Swapping "+n1);
System.out.println("After Swapping "+n2);
n1=n1+n2;
n2=n1-n2;
n1=n1-n2;
System.out.println("After Swapping Without temp variable\t"+n1);
System.out.println("After Swapping Without temp variable\t"+n2);
}
}7import java.util.Scanner;
public class OperatorsExample {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Fahrenheit");
double farenheit = sc.nextDouble();
double celsius = ((farenheit-32)*5)/9;
System.out.println("Converted celsius is " +celsius);
sc.close();
}
}8public class OperatorsExample {
public static void main(String[] args) {
int total=90;
int g=(((50*total)/100)-20);
System.out.println("Total number of girls secured A Grade: "+g);
}
} 9public class OperatorsExample {
public static void main(String[] args) {
int num= 12345;
int last= (num%100)/10;
int first=num/10000;
System.out.println("Result:" +(first+last));
}
}10import java.util.Scanner; public class OperatorsExample {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a four digit number");
int n = Integer.parseInt(sc.nextLine());
int d1=n/1000 +2;
int d2=(n/100)%10 +2;
int d3=(n/10)%10 +2;
int d4=n%10 +2;
System.out.println("Result is " +d1+d2+d3+d4);
}
} |
1public class Arithmetic {
public static void main(String[] args) {
int n=2345;
int res = (((n+8)/3)%5)*5;
System.out.println(res);
}
}2public class Assignment{
public static void main(String[] args) {
int n =2345;
n += 8;
n /= 3;
n %= 5;
n *= 5;
System.out.println(n);
}
}3,4public class Logical{
public static void main(String[] args){
int a=55;
int b=70;
System.out.println(a<50 && a<b);
System.out.println(a<50 || a<b);
}
}5public class Marks {
public static void main(String[] args){
int m1=78; int m2=45;
int m3=62;
double total=m1+m2+m3;
double percentage=(total/300)*100;
System.out.println("Total marks :"+total);
System.out.println("Percentage marks:"+percentage);
}
}6public class Swap {
public static void main(String[] args) {
int a=6,b=8;
System.out.println("Before Swapping "+a);
System.out.println("Before Swapping "+b);
int temp=a;
a=b;
b=temp;
System.out.println("After Swapping "+a);
System.out.println("After Swapping "+b);
a=a+b;
b=a-b;
a=a-b;
System.out.println("After Swapping Without temp variable\t"+a);
System.out.println("After Swapping Without temp variable\t"+b);
}
}7import java.util.Scanner;
public class TempConversion {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Fahrenheit");
double f = sc.nextDouble();
double c = ((f-32)*5)/9;
System.out.println("Converted celsius is " +c);
sc.close();
}
}8public class ClassGrade {
public static void main(String[] args) {
int total=90;
int girls=(((50*total)/100)-20);
System.out.println("Total number of girls secured A Grade: "+girls);
}
} 9public class Sum {
public static void main(String[] args) {
int n= 12345;
int l= (n%100)/10;
int f=n/10000;
System.out.println("Result:" +(f+l));
}
}10import java.util.Scanner;
public class Adding2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a four digit number");
int n = Integer.parseInt(sc.nextLine());
int d1=n/1000 +2;
int d2=(n/100)%10 +2;
int d3=(n/10)%10 +2;
int d4=n%10 +2;
System.out.println("Result is " +d1+d2+d3+d4);
}
} |





















































Uh oh!
There was an error while loading. Please reload this page.
Problem Statements
Write a program to add 8 to the number 2345 and then divide it by 3. Now, the modulus of the quotient is taken with 5 and then multiply the resultant value by 5. Display the final result.
Now, solve the above question using assignment operators (eg. +=, -=, *=).
Assign values of variables 'a' and 'b' as 55 and 70 respectively and then check if both the conditions 'a < 50' and 'a < b' are true.
Now solve the above question to check if at least one of the conditions 'a < 50' or 'a < b' is true.
If the marks of Robert in three subjects are 78,45 and 62 respectively (each out of 100 ), write a program to calculate his total marks and percentage marks.
Suppose the values of variables 'a' and 'b' are 6 and 8 respectively, write two programs to swap the values of the two variables.
1 - first program by using a third variable
2 - second program without using any third variable
( Swapping means interchanging the values of the two variables E.g.- If entered value of x is 5 and y is 10 then after swapping the value of x and y should become 10 and 5 respectively.)
Write a program to convert Fahrenheit into Celsius.
The total number of students in a class are 90 out of which 45 are boys. If 50% of the total students secured grade 'A' out of which 20 are boys, then write a program to calculate the total number of girls getting grade 'A'.
Write a program to calculate the sum of the first and the second last digit of a 5 digit.
INPUT: 12345
OUTPUT : 1+4=5
Take a 4 digit number. Write a program to display a number whose digits are 2 greater than the corresponding digits of the number TAKEN.
For example, if the number which was taken is 5696, then the displayed number should be 7818.
All reactions