Java basic Practical Programming (Part-3)

Your ‪‎future‬ is created by what you do today not tomorrow. http ...


Question(1-5)

Question(6-10)


Question 11 ):- Enter Two No and Find Even no Prime or Not.



import java.util.*;
class Prime
{
public static void main(String args[])
{
int num1,num2;
Scanner s1=new Scanner(System.in);
System.out.println("Enter a NO:");
num1=s1.nextInt();
System.out.println("Enter a NO:");
num2=s1.nextInt();
boolean flag=false;
for(int i=2;i<=num1/2;i++)
{
if(num1%i==0)
{
flag=true;
break;
}
}
if(!flag)
System.out.println("No IS Prime:");
else
System.out.println("No IS not Prime");
}
}

Question 12 ):-All Pattern Demo.



class A
{

public static void main(String args[])
{
int i,j;
for(i=0;i<=4;i++)
{
for(j=1;j<=4;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}

class A
{
public static void main(String args[])
{
int i,j,num=1;
for(i=0;i<=4;i++)
{
for(j=0;j<i;j++)
{
System.out.print(num + "");
num++;
}
System.out.println();
}

}
}


class A
{
public static void main(String args[])
{
int i,j;
for(i=1;i<5;i++)
{
for(j=5;j>i;j--)
{
System.out.print(" ");
}
for(int k=0;k<j;k++)
{
System.out.print("$");
}
}
System.out.println();
}
}




class A
{

public static void main(String args[])
{
int i,j;
for(i=1;i<5;i++)
{
for(j=5;j>i;j--)
{
System.out.print(" ");
}
for(int k=1;k<=i;k++)
{
System.out.print("*");
}
System.out.println();
}
}
}
output:
   *
   **
  ***
 ****
*/

class A
{

public static void main(String args[])
{
int i,j;
for(i=1;i<4;i++)
{
for(j=4;j>i;j--)
{
System.out.print(" ");
}
for(int k=1;k<=i;k++)
{
if(i-k==0)
System.out.print("*");
if(i-k==1)
System.out.print("$");
if(i-k==2)
System.out.print("%");
}
System.out.println();
}

}
}



Question 13 ):-Guess The NO Between 1-100.



import java.util.*;
class A
{
public static void main(String args[])
{
int number=(int) (Math.random() * 100) + 1;
Scanner pL1nm=new Scanner(System.in);
Scanner pL2nm=new Scanner(System.in);
System.out.println("Player 1 Name");
String p1nm=pL1nm.nextLine();

System.out.println("Player 2 Name");
String p2nm=pL2nm.nextLine();

System.out.println("Guess My No. Between 1-100");
Scanner b=new Scanner(System.in);
for(int counter=1;counter>0;counter++)
{
for(int i=1;i>0;i++)
{
System.out.println("Enter A no:");
int num=b.nextInt();
if(num==number)
{
System.out.println("Correct Ans:");
break;
}
else if(num<number)
{
System.out.println("No IS Low:");
System.out.println("");
}
else if(num>number)
{
System.out.println("No is High:");
System.out.println("");
}
}
if(counter%2==0)
{
System.out.println("Player 2 Win:"+p2nm);
break;
}
else
{
System.out.println("Player 1 Win:"+p1nm);
break;
}
}
}
}



Question 14 ):-Print Integer and Float value on console.



class que3
{
public static void main(String args[])
{
int a=10;
float b=20;
System.out.println("Integer value :" + a);
System.out.println("Float value :" + b);
}
}


Question 15 ):-Print String and Double value on Console.



class que4
{
public static void main(String args[])
{
String ch="J@Y";
double b=1000000;
System.out.println("String value :" + ch);
System.out.println("Double value :" + b);
}
}


Next Programs is coming Soon.... so stay Connected with us ThankYou ✌✌ .


Recon Click GIF by REFIT Revolution®

Java

Post a Comment

5 Comments