Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners programes on if....else
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Amit
programes on if....else
8 Answer(s)      3 years and 7 months ago
Posted in : Java Beginners


  1. write a program to check whether entered year is leap year or not
  2. write a program to check whether entered no. ends with 5 or not
  3. write a program to find minimum of 3 nos using nested if else.
  4. write a program to check whether entered no. is divisible by 5 or 7 or both
  5. write a program to input score of a student out of 100 and print grades using else .... if ladder

Advertisement
View Answers

March 26, 2011 at 12:54 PM


1)

import java.util.*;
class IfElse{
    public static void main(String[] args){
    Scanner input=new Scanner(System.in);
    System.out.print("Enter year: ");
    int year=input.nextInt();
    if(year%4==0){
    System.out.println("Leap Year!");
    }
    else{
    System.out.println("Not a Leap Year!");
    }
    }
}


March 26, 2011 at 12:57 PM


2)

import java.util.*;
class IfElse{
    public static void main(String[] args){
    Scanner input=new Scanner(System.in);
    System.out.print("Enter Number: ");
    int num=input.nextInt();
    String number=Integer.toString(num);
    char ch=number.charAt(number.length()-1);
    if(ch=='5'){
    System.out.println("Number ends with 5");
    }
    else{
    System.out.println("No");
    }
    }
}


March 26, 2011 at 1:04 PM


3)

import java.util.*;
class IfElse{
    public static void main(String[] args){
    Scanner input=new Scanner(System.in);
    System.out.print("Enter Number1: ");
    int x=input.nextInt();

    System.out.print("Enter Number2: ");
    int y=input.nextInt();

    System.out.print("Enter Number3: ");
    int z=input.nextInt();
    if ((x<y)&&(x<z)){
     System.out.println(x+" is smaller");
      }
      else if ((y<x)&&(y<z)){
     System.out.println(y+" is smaller");
      }

      else if ((z<y)&&(z<x)){
     System.out.println(z+" is smaller");
      }
    }
}


March 26, 2011 at 1:15 PM


4)

import java.util.*;
class IfElse{
    public static void main(String[] args){
    Scanner input=new Scanner(System.in);
    System.out.print("Enter Number: ");
    int num=input.nextInt();
    if((num%5==0)&&(num%7==0)){
        System.out.println("Number is divisible by both 5 and 7");
    }
    else if(num%5==0){
        System.out.println("Number is divisible by 5");
    }
    else if(num%7==0){
        System.out.println("Number is divisible by 7");
    }
    }
}


March 26, 2011 at 1:20 PM


5)

import java.util.*;
class IfElse{
    public static void main(String[] args){
    Scanner input=new Scanner(System.in);
    System.out.print("Enter Marks: ");
    int marks=input.nextInt();
    if(marks>90&&marks<=100){
    System.out.println("A Grade");
    }
    else if(marks>80&&marks<=90){
    System.out.println("B Grade");
    }
    else if(marks>70&&marks<=80){
    System.out.println("C Grade");
    }
    else if(marks>60&&marks<=70){
    System.out.println("D Grade");
    }
    else if(marks>40&&marks<=60){
    System.out.println("E Grade");
    }
    else{
    System.out.println("Fail");
    }
    }
}


February 2, 2012 at 4:35 PM


public static void main(String[] args) {
for(int i=1; i<100; i++){
    int div5=i%5;
    if(div5==0){
        System.out.println(i);
    }
}


February 2, 2012 at 4:40 PM


public static void main(String[] args) {
for(int i=1; i<100; i++){
    int div5=i%5;
    if(div5==0){
        System.out.println(i);
    }
}


February 2, 2012 at 4:43 PM


Donno what's wrong with me or the website... I can't get it in the right format.



Related Tutorials/Questions & Answers:
programes on if....else
programes on if....else   write a program to check whether entered... or not write a program to find minimum of 3 nos using nested if else. write... a program to input score of a student out of 100 and print grades using else
programes on strings
programes on strings   a. write a program to copy one array to another array using System.arrayCopy() method. b. write a program to check whether...]; } if(st.equalsIgnoreCase(reversedSt)){ System.out.println("String is palindrome"); } else
Advertisements
programes on for loop
programes on for loop  a. write a program to find squares and cubes of 1st 10 integers b. write a program to to calculate factorial of a no, c. write a program to print Fibonacci series d. write a program to check whether entered
programes on for loop
programes on for loop  a. write a program to find squares and cubes of 1st 10 integers b. write a program to to calculate factorial of a no, c. write a program to print Fibonacci series d. write a program to check whether entered
programes on for loop
programes on for loop  a. write a program to find squares and cubes of 1st 10 integers b. write a program to to calculate factorial of a no, c. write a program to print Fibonacci series d. write a program to check whether entered
programes on for loop
programes on for loop  a. write a program to find squares and cubes of 1st 10 integers b. write a program to to calculate factorial of a no, c. write a program to print Fibonacci series d. write a program to check whether entered
programes on methods
programes on methods   write a program to implement bubble sort write a program to demonstrate call by value and call by reference.(pass objects as parameters) write a program to calculate factorial of a no. using recursive
programes on switch
programes on switch   write a program to design menu driven arithmetic calculator write a program to print no of days in a given month   import java.util.*; class Calculator { public static void main(String[] args
programes on array
programes on array  a. write a program to find max and min element in an array of an integer b. write a program to convert decimal no. to binary and back to decimal. c. write a program to do following:- i) addition of two
programes on while loop
programes on while loop   write a program to calculate sum of an entered digit write a program to find gcd and lcm of 2 positive integers   Java sum of digits Java Find LCM and GCD
programes on do... while
programes on do... while   write a program to print reverse... is palindrome!"); } else { System.out.println("Number...; } if(check == n) System.out.println(n+" is an Armstrong Number"); else
If and else if ladder
If and else if ladder  How we can use if and else if statement?  ...) System.out.println("Grater than 100"); else if(i < 50) System.out.println("Grater than 50"); else
if/else statements
if/else statements  I'm having a hard time programming this question: code an if/else statement that test the value of a string variable named.... If the value is "UPS," code another if/else statement that tests the value
If-else not working
If-else not working  <%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %> <html> <...="SELECT REGNO,SNAME FROM sub_comb WHERE L_category='Lab'"; } else if (Lab
If-else not working
If-else not working  <%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %> <html> <...="SELECT REGNO,SNAME FROM sub_comb WHERE L_category='Lab'"; } else if (Lab
if else statement in java
if else statement in java  if else statement in java explain with example
if else condition - Java Beginners
if else condition  Please explain the if else condition in Java programming language
if else statement in java
if else statement in java  explain about simple if else statement and complex if else statement in java with an example
if else in javascript function
if else in javascript function  How can i write the else statement in JavaScript to check if the web browser is IE or not? Is there any other way to validate this way ..? Thanks
switch case instead of if else
switch case instead of if else  How to write code in switch case instead of if else in Java
ELSE STATEMENT!! - Java Beginners
ELSE STATEMENT!!  Hi! I just want to know why doesn't my else statement works? Else statement is there in the code below which is: else JOptionPane.showMessageDialog(null, n+ " is not in the array!");//doesn't work
Java if else condition
Java if else condition  its there any similar condition for (X<=5 || y<=10) please post the answer as soon as possible.... TQ
check condition in if-else block
check condition in if-else block  Hi, I want to update database with following query int i= st.executeUpdate("Insert into text_editor(words) values('"+words+"')"); how can I give a check option so only valid words are inserted
using if and else if statments
using if and else if statments  Hello everyone Hope all are well Just new here & already have a question. I have a little veg shop it sells 6... if and nested if and else if This has my head in bits for days I have the below done x6
If and else statement - JDBC
If and else statement  Dear Sir, I had created a statement...); ======================================================= how to create a if and else statement... or else it will prompt a message dialog to indicate that the word is already
IF-ELSE In JSTL
IF-ELSE In JSTL In this section we will read about implementation of if-else.... In JSTL if-else tag is not implemented directly like the if-else statement is used on the Java/JSP coding. Implementation of if-else tag in JSTL coding
Java if else
Java if else       The if-else statement is one of the widely used control flow statements while... to the programmer to handle the condition based programming. Syntax for if-else
Control Tags-If / Else If / Else
Control Tags-If / Else If / Else      ... are used for flow control such as if, else and iterate.)  'If' tag could be used by itself or with 'Else If' Tag and/or single/multiple 'Else' Tag. Create
Objective C if else statements syntax
Objective C if else statements syntax  What is the syntax of if else statements in Objective C?   Using of if else statement in Objective C There is no changes in the syntax format of if else statement. You can write
else if (selection = * 'M'); - Java Beginners
else if (selection = * 'M');  I am trying to get 2 numbers 2 multiply and i keep getting this error illegal start of expression else... + number2)); else if (selection = - 'S') System.out.println(number1
jstl if else
In this section we have discussed about how to implement if-else tag in JSTL..., as their is not default value. Hence, if-else tag is not implemented directly but is implemented with the help of some tags: <c:choose> tag : works like if-else
Advertisements
 

 

 

DMCA.com