Posts

Showing posts with the label Decision Control Instruction

write a program to check whether a triangle is valid or not, when the threeangles of the triangle are entered through the keyboard. A triangle is valid if the sumof all the three angles is equal to 180 degrees

  /*write a program to check whether a triangle is valid or not, when the three angles of the triangle are entered through the keyboard. A triangle is valid if the sum of all the three angles is equal to 180 degrees. */ package com.company ; import javax.security.sasl. SaslClient ; import java.util.Scanner ; public class Main { public static void main ( String [] args ) { // write your code here int a , b , c , sum ; //angle of triangle Scanner angle = new Scanner ( System . in ); System . out . print ( "side a : " ); a = angle . nextInt (); System . out . print ( "side b : " ); b = angle . nextInt (); System . out . print ( "side c : " ); c = angle . nextInt (); //sum of angle of trinagle sum = a + b + c ; if ( sum == 180 ) { System . out . println ( "Triangle is valid" ); } else System . out . println (

Leap year or not in java.

  Formula to calculate leap year. Identify the year we want to know if its a leap year. We then divide the year by 4 to check if its evenly divisible. Then confirm that the year is not evenly divisible by 100. Check if the year is divisible by 400. If the year is evenly divisible by 4, then the year is a leap year. If the year is only evenly divisible by 100 and not evenly divisible by 400, then the year is not a leap year. package com.company ; import java.util.Scanner ; public class Main { public static void main ( String [] args ) { // write your code here int year ; Scanner sc = new Scanner ( System . in ); System . out . print ( "Enter year : " ); year = sc . nextInt (); if (( year % 4 == 0 ) && ( year % 100 != 0 ) && ( year % 400 != 0 )) { System . out . println ( year + " is Leap Year" ); } else { System . out . println ( year + " is Not L

Number is even or odd in java

  package com.company ; import java.util.Scanner ; public class Main { public static void main ( String [] args ) { // write your code here int a ; System . out . println ( "Enter a number : " ); Scanner sc = new Scanner ( System . in ); a = sc . nextInt (); if ( a % 2 == 0 ) { System . out . println ( "Even number" ); } System . out . println ( "Odd number" ); } } Enter a number : 23 Odd number Process finished with exit code 0

If coast price and selling price of an item are input through the keyboard. Write a program to determine whether the seller has made profit or incurred loss. Also determine how much profit he made or loss he incurred.

  //.If coast price and selling price of an item are input through the keyboard. // Write a program to determine whether the seller has made profit or incurred loss. // Also determine how much profit he made or loss he incurred. package com.company ; import java.util.Scanner ; public class Main { public static void main ( String [] args ) { // write your code here int costPrice , sellingPrice , profit , loss ; Scanner sc = new Scanner ( System . in ); System . out . print ( "Enter cost price : " ); costPrice = sc . nextInt (); System . out . print ( "Enter selling price : " ); sellingPrice = sc . nextInt (); if ( sellingPrice > costPrice ) { profit = sellingPrice - costPrice ; System . out . println ( "Seller has made profit : " + profit + " ₹ " ); } else { loss = costPrice - sellingPrice ; System . o