Showing posts with label if condition in java. Show all posts
Showing posts with label if condition in java. Show all posts

Monday, September 14, 2015

Generate Prime Numbers list between 1 and 100

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package jv.prim;
/**
 * Generate Prime between 1 and 100
 * @author sm rabbi
 */

public class JvPrim {
    /**
     * @param args the command line arguments
     **/

    public static void main(String[] args) {
       
        int a,b,c;
        for(a=1;a<=100;a++)
        {
            c=1;
            for(b=2;b<=a/2;b++)
            {
                if(a%b == 0)
                {
                    c=0;
                    //System.out.println("not prime "+ a + " " + b + " " +a%b);
                    break;
                }
            }
           
            if(c==1)
            {
                System.out.println("prime= " +a);
            }
        }
    }
}
     

Saturday, September 12, 2015

Calculator using java

/*
* Write a C program for performing as calculator which allows all Arithmetic Operators with operands from
* terminal
 */
package cb_pr176;
import java.util.Scanner;
/**
 **
 * @author Arif
 **/
public class Cb_pr176 {
    /*
     * @param args the command line arguments
     */
    public static void main(String[] args) {
    // TODO code application logic here
    Scanner inp=new Scanner(System.in);
    int a,b;
    float c = 0;
    char ch;
    System.out.println("Enter Your 1st number:");
    a=inp.nextInt();
    System.out.println("Enter your 2nd number:");
    b=inp.nextInt();
    System.out.println("Enter your choice, example: +, -, *, /");
    ch=inp.next().charAt(0);
    if (ch=='+')
        c=a+b;
    else if(ch=='-')
        c=a-b;
    else if(ch=='/')
        c=(float)a/(float)b;
    else if(ch=='*')
        c=a*b;
    System.out.println("The Result is:" + c);
         
    }
  }