Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
3.java program to display all the prime numbers between 1 and 100
class prime1To100
{
public static void main()
{
int i,k,j;
for(i=1;i<100;i++)
{
k=0;
for(j=2;j<i;j++)
{
if(i%j==0)
{
k=1
break;
}
}
if(k==0)
{
System.out.println(i);
}
}
}
}
5.Java Program to Reverse a number using for, while loop and recursion
class ReverseNumberDemo
{
public static void main(String args[])
{
int num=123456789;
int reversenum =0;
while( num != 0 )
{
reversenum = reversenum * 10;
reversenum = reversenum + num%10;
num = num/10;
}
char ch = 'a';
int ascii = ch;
scan.close();
sb.reverse();
return String.valueOf(sb);
}
class Complexmain
{
public static void main(String[] a)
{
Complex C1=new Complex(4,8);
Complex C2=new Complex(5,7);
Complex C3=new Complex();
C3=C3.AddComplex(C1,C2);
System.out.println("SUM:" + C3.Real +"+i" + C3.Imag);
}
}
int rem;
String str2="";
char hex[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
while(num>0)
{
rem=num%16;
str2=hex[rem]+str2;
num=num/16;
}
System.out.println("Method 2: Decimal to hexadecimal: "+str2);
}
}
}
}
while(n!=0)
{
decimal+=((n%10)*Math.pow(2,p));
n=n/10;
p++;
}
System.out.println(decimal);
}
}
class GetMyIPAddress
{
public static void main(String args[]) throws Exception
{
InetAddress myIP=InetAddress.getLocalHost();
return false;
}
if(isPal(string))
System.out.println(string + " is a palindrome");
else
System.out.println(string + " is not a palindrome");
}
}
//2
String str2 = String.valueOf(ch);
System.out.println(str2);
}
}
// 2
String str2 = String.valueOf(ch);
System.out.println("String is: "+str2);
}
}
23.Java Program to check whether input character is vowel or consonant
public class check {
char ch = 'i';
}
}
obj.calculateArea(6.1f);
obj.calculateArea(10,22);
obj.calculateArea(6.1);
}
}